gpt4 book ai didi

git - 修复 git 双重提交历史

转载 作者:IT王子 更新时间:2023-10-29 01:27:16 25 4
gpt4 key购买 nike

前几天我不得不运行 git filter-branch。我按照说明 on github ,但出了点问题。我认为团队中有人没有在本地分支上运行 rebase,而是 merge 了更改。从那以后,提交日志充满了双重提交,例如:

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 post建议按原样保留它,但为了后代,我宁愿有一个干净的提交历史。

最佳答案

完成的命令是:

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 应用所有两个更改,然后将您带回编辑器以 merge 三个提交消息:

# 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

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

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

关于git - 修复 git 双重提交历史,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22817360/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com