简体   繁体   English

从历史记录中删除合并提交

[英]Remove Merge Commits from History

After having a look at a gazillions of websites and StackExchange questions, I want to add a further question about Git.在查看了无数网站和 StackExchange 问题之后,我想再补充一个关于 Git 的问题。 I think that this answer comes quite close to what I want, but I was not successful.我认为这个答案非常接近我想要的,但我没有成功。

Gitg displays my repository as having branches (ok), but one of these branches was merged into another one twice. Gitg 将我的存储库显示为具有分支(好的),但是这些分支之一被合并到另一个分支两次。 I want to modify the history by just removing the commits which do these merges.我想通过删除执行这些合并的提交来修改历史记录。 These commits have a message beginning with "Merge branches" and "Merge branch".这些提交的消息以“合并分支”和“合并分支”开头。 All I want is to just keep these branches parallel, unmerged.我想要的只是保持这些分支平行,未合并。 Also, there were commits to these branches after these merges which have to be kept intact.此外,在这些合并之后,对这些分支的提交必须保持不变。 These branches do not touch the same files, so there should not be a conflict.这些分支不涉及相同的文件,因此不应该有冲突。

Please see here the screenshot of Gitg.请在此处查看 Gitg 的屏幕截图。 So, I want these branch drawn in blue not connect to the branch drawn in green.所以,我希望这些以蓝色绘制的分支不连接到以绿色绘制的分支。 How can I do this (for manipulating the repository, I am using the command line, of course).我该怎么做(当然,为了操作存储库,我使用的是命令行)。

Gitg 显示合并的分支

If the history after those merges is a straight line, you can try this:如果这些合并后的历史是一条直线,你可以试试这个:

git checkout revision-before-first-merge
git cherry-pick id-of-second-merge..the-branch
# now you have a history like what you want
# if you like how it looks, then it's time to move the branch
git branch -f the-branch # set the branch over here
git checkout the-branch

Warning : this is rewriting history of this branch which is technically possible (as we just saw) but it has implications.警告:这是重写这个分支的历史,这在技术上是可行的(正如我们刚刚看到的),但它有影响。

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

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