Git 如何在挤压时忽略提交
我有3次提交,我想在重定为1的同时跳过提交-2 说 我做了git rebase-我头~3Git 如何在挤压时忽略提交,git,Git,我有3次提交,我想在重定为1的同时跳过提交-2 说 我做了git rebase-我头~3 pick commit -1 pick commit -2 squash commit -3 我试过这样做(删除了pick commit-2),但从git日志中删除了commit-2本身:( 有人请帮助我如何仅使用命令挤压提交1和提交3。如果我理解正确,只需重新排列提交: pick commit -1 squash commit -3 pick commit -2 这将把commit-2放在-1和-3之
pick commit -1
pick commit -2
squash commit -3
我试过这样做(删除了pick commit-2),但从git日志中删除了commit-2本身:(
有人请帮助我如何仅使用命令挤压提交1和提交3。如果我理解正确,只需重新排列提交:
pick commit -1
squash commit -3
pick commit -2
这将把
commit-2
放在-1
和-3
之后;如果您希望将-2
放在前面,则将其放在前面。(提交从上到下进行评估。)如果您不关心分支和提交的历史记录,您可以从commit-4开始一个分支;cherry pick 1和3,挤压它们,然后cherry pick commit-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
简单,重新排列行:
pick 1
squash 3
pick 2
这将重新设置历史的基础,将3压缩为1,然后移动提交2
从帮助文本中:
这些行可以重新排序;它们从上到下执行
当你说“跳过提交2”时,你的意思是你想将3压缩为1,并在压缩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
pick 1
squash 3
pick 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