繁体   English   中英

我如何在早些时候git squash一起提交?

[英]How do I git squash earlier commits together?

我在我的分支上有大约10个提交,让我们说ID 1到10。我想要将4,5和6的提交压缩在一起,但其余部分保持不变。 我找到的每个教程都从当前的HEAD开始,然后使用git rebase -i HEAD~(x amount)向后退。 但是如何在之前的提交中启动rebase并指定一个范围,例如git rebase -i 6 ... 4?

谢谢

只需做一个交互式的rebase,修复你想要压缩或修复的提交。

git rebase -i HEAD~10

pick a4461d3 
pick d998164 
pick 0a1f6e1 
f 310ba9d 
f 60b7e01
f 7baef60
pick bb9a551
pick badbad1
pick fd9a10c
pick 59ed66f

# Rebase e7e1369..60b7e01 onto fd9a10c (10 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

那么,@ jaredr已经回答了你的问题。 来到问题的第二部分,GIT不提供这样的命令( git rebase -i 4..6)。 事实上它不应该! 想象一下,如果GIT开始提供这样的命令(必须在某些提交上执行操作并堆叠其他命令),GIT必须执行多少操作。正确合并会增加额外的复杂性。因此,它将此作业转移给用户本身/她是更了解代码的人。)此外,它提供了帮助机制,如Git squash ,您可以暂时转储您的提交并处理其他事情。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM