[英]How to combine git commits
In my local GIT repository, I have the following commits: 在我的本地GIT存储库中,我有以下提交:
A --> B --> C --> D A - > B - > C - > D.
(Where D is the head) (D是头部)
I would like to combine/squash B and C into a single commit. 我想将B和C组合/压缩成一个提交。 How could I do that?
我怎么能这样做?
Thanks. 谢谢。
Use this command: 使用此命令:
git rebase -i A ;# where A is A's commit hash
In the interactive editor, change the the lines, which should look something like this: 在交互式编辑器中,更改行,如下所示:
pick c7787af A
pick f9d9262 B
pick 6c363d0 C
pick 40f657d D
To this: 对此:
pick c7787af A
pick f9d9262 B
squash 6c363d0 C
pick 40f657d D
If you'd prefer to abandon C's commit message, but still squash the commit, use this: 如果您更愿意放弃C的提交消息,但仍然压缩提交,请使用:
pick c7787af A
pick f9d9262 B
fixup 6c363d0 C
pick 40f657d D
Never rebase a branch you've already shared with collaborators. 切勿重新绑定您已与协作者共享的分支。 The action changes SHA1 hashes, and results in non-fast-forward updates.
该操作会更改SHA1哈希值,并导致非快进更新。
As Jason noted in comments, an alternative syntax is git rebase -i HEAD~4
. 正如杰森在评论中指出的那样,另一种语法是
git rebase -i HEAD~4
。 When you're rebasing recent history to squash commits (ie when it's easy to count parents back in time), this avoids the trouble of looking up A
's hash. 当您将最近的历史记录重新设定为压缩提交时(即,很容易将父母及时计算回来),这可以避免查找
A
哈希的麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.