Git从提交N重新定位为提交B

时间:2019-01-17 13:25:34

标签: git git-bash

是否可以仅对N个提交列表中的特定提交进行重新设置?

我总共有36个提交,并且想从提交36压缩到提交12个说(从36到12,它们都是一个用户的提交,并且都是针对单个功能的),该怎么做? >

1 个答案:

答案 0 :(得分:3)

您可以使用interactive rebase进行此操作。

git checkout <branch_with_commits>
git rebase -i HEAD~36

这将打开一个编辑器,其中所有提交都将重新设置基础,并对每个提交执行如下操作:

pick f7f3f6d changed my name a bit
pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file

# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# 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
#
# 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

对于您要压缩的提交,将动作更改为南瓜(或其他要执行的动作)。保存并关闭编辑器以应用更改。