同一提交中的多个分支

Multiple branches in the same commit

我有一个包含多个(不需要的)分支的提交,通过 git log --graph 我得到了这个:

commit 417bb7dfd7d7230fd1c859414d2aa231e72e24e6 (HEAD -> Feature1, master, Feature2)

如何将 Feature1、Feature2 分支从提交 417bb7dfd7d7230fd1c859414d2aa231e72e24e6 移动到不同的提交?

感谢您的帮助。

这好像是误会了

这些分支不在提交中

在git中,分支是指向提交的标签。一个提交可以有任意数量(零个、四个、一千个等等)的分支指向它。

A---B---C---D
     \   \   \
      \   \   master
       \   \
        \   branch-abc
         \
          branch-xyz

在上面,masterbranch-abcbranch-xyz 恰好指向不同的提交,但是如果您这样做了

git checkout branch-abc
git merge master

然后你会得到

A---B---C---D
     \       \
      \       master, branch-abc
       \    
        branch-xyz

...其中,是的,masterbranch-abc do 指向相同的提交。


如果出于任何原因,您 需要移动或删除一个分支,这很容易(但话又说回来,我必须强调重要的部分,理解什么分支)

# move a branch to commit abc123 (when the branch is NOT checked out)
git branch -f my_branch abc123

# or if the branch IS checked out
git reset --hard abc123

# delete a branch
git branch -d my_branch

# ...which will complain in case the branch isn't fully merged yet
# in which case you can then force it
git branch -D my_branch