给定SHA的开始和结束位置,我如何将一系列git commit压缩在一起 [英] How can I squash a range of git commits together given starting and ending SHA's
问题描述
我有一个分支,大约有20个提交.
I have a branch with about 20 commits.
分支上的第一个SHA是bc3c488...
分支上的最后一个SHA是2c2be6...
The first SHA on the branch is bc3c488...
The last SHA on the branch is 2c2be6...
如何将所有提交合并在一起?
How can I merge all the commits together?
我要在不使用交互式变基的情况下执行此操作,因为提交的次数太多.
I want to do this without using interactive rebase as there are so many commits.
我需要一个github Pull Request来合并我的提交.
I need this for a github Pull Request where I am being asked to merge my commits.
需要执行此操作而无需执行git merge --squash,因为我需要在本地进行壁球压缩,而另一个开发人员进行合并,希望我在合并之前先进行壁球压缩.
Need to do this without doing a git merge --squash as I need to squash locally and another developer does the merge and wants me to do the squash first before merging.
推荐答案
如果第一个SHA是HEAD,您也可以使用以下方法:
If the first SHA is HEAD you can also use this approach:
git reset --soft $OLD_SHA; git add -A; git commit --amend --no-edit
请注意,此命令将更改存储库的历史记录.
be careful, this command will change the history of the repo.
如果您要压缩历史记录中的提交,则:
If you want to squash commits that are in the middle of your history:
|---* --- 0 --- 1 ---- 2 --- 3 --- * --- * --- * --- HEAD
就像在这种情况下一样,提交1、2和3
like in this case the commits 1, 2 and 3
我真的建议使用rebase -i
这篇关于给定SHA的开始和结束位置,我如何将一系列git commit压缩在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!