修复git双重提交历史 [英] Fixing git double-commit history

查看:146
本文介绍了修复git双重提交历史的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前几天我必须运行 git filter-branch 。我遵循 on github 的指示,但出现了问题。我认为团队中的某人没有在本地分支上运行rebase,而是合并了更改。从那以后,提交日志被双提交填充,例如:

 提交b0c03ec925c0b97150594a99861d8f21fd3ab22d 
作者:XXX
日期:Wed Mar 19 17:01:52 2014 -0400

删除了模板中的大多数纯文本修饰符

提交f30c21d21b5ea715a99b0844793cb4b5f5df97a1
作者:XXX
日期:Wed Mar 19 17:01:52 2014 -0400

删除模板中最清晰的修正

commit 2346be43d0e02d3987331f0a9eeb2f12cd698ede
作者:XXX
日期:Wed Mar 19 16:40:26 2014 -0400

新的重定向逻辑

提交1383070b31bde1aaa9eda7c2a9bcb598dd72247b
合并:d1e2eb6 94e07fe
作者:XXX
日期:Wed Mar 19 16:28:41 2014 -0400

将github.com:xxx/xxx的分支'develop'合并为develop

commit 79ce7824688cf2a71efd9ff82e3c7a71d53af229
合并:6079061 1ed3967
作者:XXX
日期:Wed Mar 19 16:28:41 2014 -0400

合并分支'develop'of github .com:xxx / xxx into develop

commit d1e2eb645a4fe2a1b3986082d0409b4075a0dbc9
作者:XXX
日期:Wed Mar 19 16:28:36 2014 -0400

修复公司列表页面和代码重构的响应失效问题。

提交6079061f6ef1f856f94d92bc0fdacf18854b8a89
作者:XXX
日期:Wed Mar 19 16:28:36 2014 -0400

修复了公司列表页面和代码重构。

奇怪的是,并非所有的提交都是双倍的,比如上面的新的重定向逻辑。有什么我可以解决这个问题吗?这是相对温和的,但现在我们的提交历史看起来像垃圾。这个 SO帖子建议只是保持原样,但我宁愿有一个

解决方案

完成该命令的命令是:

  git rebase -i HEAD〜7 

这会打开你的编辑器,如下所示:

  pick f392171删除了模板中的大多数纯文本
pick ba9dd9a Removed模板中最清晰的修正
选择df71a27 Unew重定向逻辑
选择79ce782合并分支github.com:xxx/xxx的'develop'开发
选择1383070合并分支'develop'of github.com: xxx / xxx开发
...

现在你可以告诉git如何处理每次提交。让我们保持提交f392171,我们添加了我们的功能。我们将压缩以下两个提交到第一个提交 - 留给我们一个干净。



更改您的文件到这个:

  pick f392171删除了模板中的大多数修正符
squash ba9dd9a删除了模板中的大多数修正符
pick df71a27 Unew重定向逻辑
选择79ce782合并分支'开发'github.com:xxx/xxx开发
压缩1383070合并github.com:xxx/xxx分支'develop'开发

保存并退出编辑器时,Git会应用所有两项更改,然后将您重新放回编辑器以合并三个提交消息:

 #这是提交的组合。 
#第一个提交的信息是:
在模板中删除了大多数的修正符

#这是第二个提交信息:

删除了模板中的大多数修正符

完成后,保存并退出编辑器。 Git现在将压缩提交到一个。所有完成!



然后您必须做
$ b $ pre $ g $ push原点您的分支-f

强制您的本地提交更改到远程分支。



注意:您必须对每个重复的提交进行压缩。


I had to do run git filter-branch the other day. I followed the instructions on github, but something went wrong. I think someone on the team didn't run rebase on a local branch, and instead merged the changes. Ever since, the commit log is filled with double-commits, e.g.:

commit b0c03ec925c0b97150594a99861d8f21fd3ab22d
Author: XXX
Date:   Wed Mar 19 17:01:52 2014 -0400

    Removed most clearfixs in templates

commit f30c21d21b5ea715a99b0844793cb4b5f5df97a1
Author: XXX
Date:   Wed Mar 19 17:01:52 2014 -0400

    Removed most clearfixs in templates

commit 2346be43d0e02d3987331f0a9eeb2f12cd698ede
Author: XXX
Date:   Wed Mar 19 16:40:26 2014 -0400

    new redirect logic

commit 1383070b31bde1aaa9eda7c2a9bcb598dd72247b
Merge: d1e2eb6 94e07fe
Author: XXX
Date:   Wed Mar 19 16:28:41 2014 -0400

    Merge branch 'develop' of github.com:xxx/xxx into develop

commit 79ce7824688cf2a71efd9ff82e3c7a71d53af229
Merge: 6079061 1ed3967
Author: XXX
Date:   Wed Mar 19 16:28:41 2014 -0400

    Merge branch 'develop' of github.com:xxx/xxx into develop

commit d1e2eb645a4fe2a1b3986082d0409b4075a0dbc9
Author: XXX
Date:   Wed Mar 19 16:28:36 2014 -0400

    Fixed broken responsiveness for companies listing page and code refactoring.

commit 6079061f6ef1f856f94d92bc0fdacf18854b8a89
Author: XXX
Date:   Wed Mar 19 16:28:36 2014 -0400

    Fixed broken responsiveness for companies listing page and code refactoring.

Weirdly enough, not all the commits are doubled-up, such as "new redirect logic" above. Is there anything I can do to fix this? It's relatively benign, but now our commit history looks like crap. This SO post suggested just leaving it as-is, but I'd rather have a clean commit history for the sake of posterity.

解决方案

The command to accomplish that is:

git rebase -i HEAD~7

This will open up your editor with something like this:

pick f392171 Removed most clearfixs in templates
pick ba9dd9a Removed most clearfixs in templates
pick df71a27 Unew redirect logic
pick 79ce782 Merge branch 'develop' of github.com:xxx/xxx into develop
pick 1383070 Merge branch 'develop' of github.com:xxx/xxx into develop
...

Now you can tell git what to do with each commit. Let's keep the commit f392171, the one where we added our feature. We'll squash the following two commits into the first one - leaving us with one clean.

Change your file to this:

pick f392171 Removed most clearfixs in templates
squash ba9dd9a Removed most clearfixs in templates
pick df71a27 Unew redirect logic
pick 79ce782 Merge branch 'develop' of github.com:xxx/xxx into develop
squash 1383070 Merge branch 'develop' of github.com:xxx/xxx into develop

When you save and exit the editor, Git applies all two changes and then puts you back into the editor to merge the three commit messages:

# This is a combination of  commits.
# The first commit's message is:
Removed most clearfixs in templates

# This is the 2nd commit message:

Removed most clearfixs in templates

When done, save and quit your editor. Git will now squash the commits into one. All done!

Then you have to do

git push origin your-branch -f

to force your locally commits changes into remote branch.

Note: You have to do a squash to every duplicated commit.

这篇关于修复git双重提交历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆