前git filter-branch
几天我不得不跑.我按照github上的说明进行操作,但出了点问题.我认为团队中的某个人没有在本地分支上运行rebase,而是合并了这些更改.从那时起,提交日志就会填充双重提交,例如:
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.
奇怪的是,并非所有提交都是双倍的,例如上面的"新重定向逻辑".有什么办法可以解决这个问题吗?这是相对温和的,但现在我们的提交历史看起来像垃圾.这篇SO帖子建议将其保留原样,但为了后代,我宁愿有一个干净的提交历史.
完成该任务的命令是:
git rebase -i HEAD~7
这将打开你的编辑器,如下所示:
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 ...
现在你可以告诉git如何处理每个提交.让我们保留提交f392171,我们添加了我们的功能.我们将以下两个提交压缩到第一个 - 让我们一个干净.
将您的文件更改为:
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
当您保存并退出编辑器时,Git会应用所有两个更改,然后返回编辑器以合并三个提交消息:
# 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
完成后,保存并退出编辑器.Git现在将提交压缩成一个.全部完成!
然后你必须这样做
git push origin your-branch -f
强制您将本地提交更改到远程分支.
注意:您必须对每个重复的提交进行压缩.