问题描述
在我的本地GIT仓库中,我有以下提交:
- > B - > C - > D
(其中D是头部)
我想将B和C合并/压缩为单个提交。
我该怎么做?
谢谢。
使用此命令:
git rebase -i A;#其中A是A的提交散列值
在交互式编辑器中,更改线条,如下所示:
挑选c7787af A
挑选f9d9262 B
挑选6c363d0 C
挑选40f657d D
至此:
选取c7787af A
pick f9d9262 B
squash 6c363d0 C
pick 40f657d D
如果您愿意喜欢放弃C的提交消息,但仍然压缩提交,使用此:
选择c7787af A
选择f9d9262 B
fixup 6c363d0 C
pick 40f657d D
永远重新分配您已与合作者共享的分支。正如Jason在评论中指出的那样,另一种语法是 git rebase - 这是一个非常快速的更新。
A
的哈希值的麻烦。 In my local GIT repository, I have the following commits:
A --> B --> C --> D
(Where D is the head)
I would like to combine/squash B and C into a single commit.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:
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.
As Jason noted in comments, an alternative syntax is git rebase -i HEAD~4
. When you're rebasing recent history to squash commits (i.e. when it's easy to count parents back in time), this avoids the trouble of looking up A
's hash.
这篇关于如何结合git提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!