github)从合并中删除提交

时间:2012-09-09 13:41:09

标签: git merge commit rebase

我的问题类似于git remove commit from a merge,但我不能按照那里提出的说明进行操作,因为我的存储库历史有点不同。

我正在使用github上的开源存储库。几个月后,我想更新我的本地存储库,我错误地做了一个无用的合并提交。历史如下:

* commit 3d542ddb64e6474a10dfface24defc69b713a295
| Author: TD
| 
|     fixed typo in dependency_injection/compilation chapter
|    
*   commit 34db3b8c08e5c5d3be4021076716ed90187fe5fb
|\  Merge: b8b73fb 7cc08f4
| | Author: TD
| | 
| |     Merge remote-tracking branch 'upstream/master'
| |   
| * commit 7cc08f476b7ac5610b1eb5b5db5182d18e35a9e9
| | Author: RW
| | 
| |     [#1654] Tweaking comments
...

只有一次提交我的小改动,但有两个。我只是想删除34db3b8c0 ...合并提交。我知道我应该尝试交互式rebase,但我不知道如何设置它。当我尝试

git rebase -i HEAD~2

我收到了过去提交的大量列表:

pick bbfbddb Add the new "strict_requirements"
pick 31bb8a9 [reference] Tweaking note about strict_requirements
pick fb4d621 [Cookbook][Extension] Fixed typo in functions name
pick d8d1d86 Fixing index typo
# lots and lots of commits in the history here
pick c734436 Fixed indentation.
pick ca8d884 Update cookbook/logging/channels_handlers.rst
pick 7cc08f4 [#1654] Tweaking comments in channel handlers doc to point to reference
pick 3d542dd fixed typo in dependency_injection/compilation chapter: should be contAiner instead of continer

# Rebase b8b73fb..3d542dd onto b8b73fb
#
# Commands:
...

但是当我尝试时:

git rebase -i HEAD~1

(想要一个更短的清单)我只得到一次提交:

pick 3d542dd fixed typo in dependency_injection/compilation chapter: should be contAiner instead of continer

据我了解,我应该使用交互式rebase压缩合并提交34db3b8c08 ...对不起?

感谢您的帮助。

3 个答案:

答案 0 :(得分:3)

试试git rebase upstream/master。因此,您的提交将应用于远程主服务器。合并提交将被删除无用。

答案 1 :(得分:3)

您要做的是接受自合并以来的所有更改,并在合并之前将它们重新绑定到提交上:

git rebase --onto 34db3b8^ 34db3b8 master

其中“34db3b8”是您要消除的合并提交,“master”是您想要消除它的分支。这将重写分支,跳过合并提交并重放其后的所有内容。

答案 2 :(得分:2)

最简单的方法是将分支HEAD重置为上游HEAD并强制推送到原点

git reset --hard HEAD upstream/master

git push -f origin master