本文介绍了将git父指针设置为不同的父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在过去提交了一个指向一位父母的提交,但是我想更改它指向的父代,那么我该如何去做?

解决方案

使用 在当前分支中位于< new-parent>的顶部。

If I have a commit in the past that points to one parent, but I want to change the parent that it points to, how would I go about doing that?

Using git rebase. It's the generic "take commit(s) and plop it/them on a different parent (base)" command in Git.

Some things to know, however:

  1. Since commit SHAs involve their parents, when you change the parent of a given commit, its SHA will change - as will the SHAs of all commits which come after it (more recent than it) in the line of development.

  2. If you're working with other people, and you've already pushed the commit in question public to where they've pulled it, modifying the commit is probably a Bad Idea™. This is due to #1, and thus the resulting confusion the other users' repositories will encounter when trying to figure out what happened due to your SHAs no longer matching theirs for the "same" commits. (See the "RECOVERING FROM UPSTREAM REBASE" section of the linked man page for details.)

That said, if you're currently on a branch with some commits that you want to move to a new parent, it'd look something like this:

git rebase --onto <new-parent> <old-parent>

That will move everything after <old-parent> in the current branch to sit on top of <new-parent> instead.

这篇关于将git父指针设置为不同的父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:46