我如何将我最近的承诺转移到一个新的分支机构,并在这些承诺完成之前重新定义主? 例如:

master A - B - C - D - E

为此:

newbranch     C - D - E
             /
master A - B 

当前回答

我很惊讶,没有人这样推荐:

git checkout master
git checkout <commit hash from which you want to split>
git checkout -b new_branch
git rebase master
git checkout master
git reset --hard <commit hash you splitted>

要解释:

步骤我们检查的承诺,我们想要分裂,然后从这个承诺创建一个新的分支,做 rebase 将同步 new_branch 和 master. 因此,现在我们有两个相同的分支与同样的承诺重新设置在 master,我们清理后分裂列表项目后最后的承诺

其他回答

最简单的方式就是这样做:

任命主分支到您的新分支(假设您在主分支):

git branch -m newbranch

2、从你想要的承诺中创建主分支:

git checkout -b master <seven_char_commit_id>

例如 git checkout -b master a34bc22

注意:新行业的上流将是起源/主流。

这不是在技术上“移动”它们,但它有相同的效果:

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)

我怎么能离开这

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

只有在这种情况下:

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

你可以做到这一点只是我使用的3个简单步骤。

1)做一个新的分支,你想承诺你最近的更新。

git branch <branch name> 品牌名称

2) 查找最近的承诺 ID 为承诺新分支。

登录

3) 复制的承诺ID 注意,最最近的承诺列表发生在顶部,所以你可以找到你的承诺。

git cherry-pick d34bcef232f6c...

你也可以提供一些承诺ID的范围。

git cherry-pick d34bcef...86d2aec

现在你的工作完成了,如果你选择了正确的ID和正确的分支,那么你会成功,所以在做这件事之前要小心,否则另一个问题可能会出现。

现在你可以按下你的代码

点击Push