我如何将我最近的承诺转移到一个新的分支机构,并在这些承诺完成之前重新定义主? 例如:
master A - B - C - D - E
为此:
newbranch C - D - E
/
master A - B
我如何将我最近的承诺转移到一个新的分支机构,并在这些承诺完成之前重新定义主? 例如:
master A - B - C - D - E
为此:
newbranch C - D - E
/
master A - B
当前回答
如果你只需要将所有的无缝承诺转移到一个新的分支,那么你只需要,
创建一个新的分支从当前一个 :git 分支新分支名 推你的新分支: git 推起源新分支名 转换你的旧(当前)分支到最后一个推 / 稳定状态: git 重新设置 - 硬起源 / 旧分支名
有些人也有其他上流而不是起源,他们应该使用适当的上流。
其他回答
我怎么能离开这
A - B - C - D - E
|
master
到此?
A - B - C - D - E
| |
master newbranch
兩個命令
吉特分支 -m 主新分支
给予
A - B - C - D - E
|
newbranch
和
吉特分支大师B
给予
A - B - C - D - E
| |
master newbranch
还有另一种方法来做到这一点,只使用2个命令,同时保持您的当前工作树无缝。
git checkout -b newbranch # switch to a new branch
git branch -f master HEAD~3 # make master point to some older commit
旧版本 - 在我学到 git branch -f 之前
git checkout -b newbranch # switch to a new branch
git push . +HEAD~3:master # make master point to some older commit
能夠推到. 是一個好技巧知道。
使用Emacs' git porcelain Magit,您可以通过击中b s(magit-branch-spinoff)。您将被要求为您的新分支输入一个名称,一旦您击中,voila。
《魔法文档》:
这个命令创建并检查一个新的分支开始并跟踪当前分支. 该分支反过来重新设置到最后一个分支它与其上流共享. 如果当前分支没有上流或没有不冲动的分支,那么新的分支是创建的任何情况下,以前的当前分支没有被触摸。
这不是在技术上“移动”它们,但它有相同的效果:
A--B--C (branch-foo)
\ ^-- I wanted them here!
\
D--E--F--G (branch-bar)
^--^--^-- Opps wrong branch!
While on branch-bar:
$ git reset --hard D # remember the SHAs for E, F, G (or E and G for a range)
A--B--C (branch-foo)
\
\
D-(E--F--G) detached
^-- (branch-bar)
Switch to branch-foo
$ git cherry-pick E..G
A--B--C--E'--F'--G' (branch-foo)
\ E--F--G detached (This can be ignored)
\ /
D--H--I (branch-bar)
Now you won't need to worry about the detached branch because it is basically
like they are in the trash can waiting for the day it gets garbage collected.
Eventually some time in the far future it will look like:
A--B--C--E'--F'--G'--L--M--N--... (branch-foo)
\
\
D--H--I--J--K--.... (branch-bar)
只有在这种情况下:
Branch one: A B C D E F J L M
\ (Merge)
Branch two: G I K N
我表演了:
git branch newbranch
git reset --hard HEAD~8
git checkout newbranch
我希望承诺我会成为头,但承诺是现在的。
要确保在历史上登上正确的位置,就更容易与承诺的哈希工作。
git branch newbranch
git reset --hard #########
git checkout newbranch