简体   繁体   English

Git删除分支之间的提交

[英]Git remove commits between branches



I have the following history in Git: 我在Git中有以下历史记录:

(master) A - B - C
                  \
(dev)              D - E - F - G - H - I

I would like to create something like this: 我想创建这样的东西:

(master) A - B - C
                 | \
(patch_1)        |- E' - G' (G' shouldn't contain the changes happened at F commit)
(patch_2)        |- D' - F' (F' shouldn't contain the changes happened at E commit)
(dev)            |- D - E - F - G - H - I

Is it possible to create something like this? 是否可以创建这样的东西?

If it is not possible what is better from the following option: 如果不可能,则可以使用以下选项更好:
1. Rewrite the code from the beginning? 1.从头开始重写代码?
2. Squash all these commits into one with a "nice" and big commit message? 2.用“ nice”和大提交消息将所有这些提交压缩为一个?

One possible solution I can think of is using git cherry-pick. 我能想到的一种可能的解决方案是使用git cherry-pick。

  1. Change to dev branch, get SHA-1 commits of E, G, D and F (using git log --oneline). 转到dev分支,获取E,G,D和F的SHA-1提交(使用git log --oneline)。

  2. From master branch, create patch_1 branch and issue git cherry-pick command with SHA-1 of E, G (as arguments). 在master分支中,创建patch_1分支,并使用E,G的SHA-1(作为参数)发出git cherry-pick命令。

  3. From master branch, create patch_2 branch and issue git cherry-pick command with SHA-1 of D, F (as arguments). 从master分支创建patch_2分支,并使用D,F的SHA-1(作为参数)发出git cherry-pick命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM