交互式 rebase 和普通 rebase 有什么区别?
What is the difference between interactive rebase and normal rebase?
interactive rebase 有什么不同,比如:
git rebase -i HEAD~3
并且在没有 -i
的情况下变基:
git rebase HEAD~3
交互式变基将打开一个编辑器,其中包含将要更改的提交列表。此列表接受命令,允许用户在启动变基操作之前编辑列表。
正如 Thomas Edwards 评论的那样,这些文档在这里很有帮助。 pro git book (specifically the sections on rebasing and rewriting history.
rebase 的核心是检查根提交并逐个应用一系列提交。
当您进行常规变基 (git rebase HEAD~3
) 时,这会自动发生。
然而,当您执行交互式变基时 (git rebase -i HEAD~3
),您将有机会编辑提交。
这看起来像是修改提交消息、将提交压缩在一起、编辑提交中的更改甚至完全删除提交!
- 正常变基:当前分支只是变基。没有从用户那里得到反馈
- Interactive Rebase:用户可以选择处理当前分支中的提交。用户可以 re-order 提交和如下所示的其他选项:
命令:
- p, pick = 使用提交
- r, reword = 使用提交,但编辑提交信息
- e, edit = 使用commit,但停止修改
- s, squash = 使用提交,但合并到之前的提交中
- f, fixup = 喜欢 "squash",但丢弃此提交的日志消息
- x, exec = 运行 命令(该行的其余部分)使用 shell
- d, drop = 删除提交
Normal Rebase
它不接受任何用户输入,因此它从分支中挑选所有提交而不做任何修改并应用所有提交。
Interactive Rebase
它会在你面前打开编辑器,这样我们就可以以任何我们想要的方式对每个提交进行任何类型的修改。如下所示
Interactive Rebase Commit Editor
pick <commit_hash> <commit_message>
pick 42522f0 add stack implementation
# Rebase 6aa416b..42522f0 onto 6aa416b (1 command)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# 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.
在正常的 rebase 中,它会自动完成,默认情况下选择所有提交而不是任何修改(rebase、编辑或删除等)
如果您只有一个提交,最好使用 normal rebase
,反之亦然。
interactive rebase 有什么不同,比如:
git rebase -i HEAD~3
并且在没有 -i
的情况下变基:
git rebase HEAD~3
交互式变基将打开一个编辑器,其中包含将要更改的提交列表。此列表接受命令,允许用户在启动变基操作之前编辑列表。
正如 Thomas Edwards 评论的那样,这些文档在这里很有帮助。 pro git book (specifically the sections on rebasing and rewriting history.
rebase 的核心是检查根提交并逐个应用一系列提交。
当您进行常规变基 (git rebase HEAD~3
) 时,这会自动发生。
然而,当您执行交互式变基时 (git rebase -i HEAD~3
),您将有机会编辑提交。
这看起来像是修改提交消息、将提交压缩在一起、编辑提交中的更改甚至完全删除提交!
- 正常变基:当前分支只是变基。没有从用户那里得到反馈
- Interactive Rebase:用户可以选择处理当前分支中的提交。用户可以 re-order 提交和如下所示的其他选项:
命令:
- p, pick = 使用提交
- r, reword = 使用提交,但编辑提交信息
- e, edit = 使用commit,但停止修改
- s, squash = 使用提交,但合并到之前的提交中
- f, fixup = 喜欢 "squash",但丢弃此提交的日志消息
- x, exec = 运行 命令(该行的其余部分)使用 shell
- d, drop = 删除提交
Normal Rebase
它不接受任何用户输入,因此它从分支中挑选所有提交而不做任何修改并应用所有提交。
Interactive Rebase
它会在你面前打开编辑器,这样我们就可以以任何我们想要的方式对每个提交进行任何类型的修改。如下所示
Interactive Rebase Commit Editor
pick <commit_hash> <commit_message>
pick 42522f0 add stack implementation
# Rebase 6aa416b..42522f0 onto 6aa416b (1 command)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# 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.
在正常的 rebase 中,它会自动完成,默认情况下选择所有提交而不是任何修改(rebase、编辑或删除等)
如果您只有一个提交,最好使用 normal rebase
,反之亦然。