我有3个提交,我想跳过提交-2,而变基为1 说
commit -1
commit -2
commit -3
我做了git rebase -i HEAD~3
pick commit -1
pick commit -2
squash commit -3
我试过这样(删除了选择提交-2)但是从git log中删除了提交-2本身:(
git rebase -i HEAD~3
pick commit -1
squash commit -3
有人请帮助我如何使用命令压缩提交1和提交3。
答案 0 :(得分:3)
如果我理解正确,只需重新排序提交:
pick commit -1
squash commit -3
pick commit -2
这会在commit -2
和-1
之后放置-3
;如果你想要它,请将-2
放在首位。 (提交从上到下进行评估。)
答案 1 :(得分:1)
简单,重新排序:
pick 1
squash 3
pick 2
这会将历史记录3压缩为1并在之后移动提交2。
来自帮助文本:
这些线可以重新订购;它们是从上到下执行的。
# Rebase 25c328e..a038737 onto 25c328e (2 commands)
#
# 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
答案 2 :(得分:0)
如果你不关心分支和提交的历史;你可以从commit-4开始一个分支;樱桃挑选1和3,挤压他们然后樱桃挑选承诺-2。您将进入一个新分支,但它将获得您需要的最终结果。此外,我认为提交不会有冲突。
commit-1
commit-2
commit-3
commit-4
git checkout commit-4
git checkout -b newbranch name
git cherry-pick commit-3 commit-1
git rebase and do the squash
git cherry-pick commit-2