在 Git 中变基时,提交会丢失什么?


#
# 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.

使用提交哈希注释掉该行与使用 DROP 关键字相同吗?
我想重新调整我的拉取请求的基数,以便它只提交一次提交。

是的,drop和删除的行都会导致删除提交。从文档中:

要删除提交,请将命令"pick"替换为"drop",或者只是删除匹配的行

但也有很小的差异。例如:

删除所有行
  1. 将中止变基,因此这与删除所有行不同
  2. 可以启用一项检查以在缺少行时发出警告/错误:

    rebase.missingCommitsCheck: 如果设置为"warn",git rebase -i 将在删除某些提交(例如删除一行(时打印警告,但变基仍将继续。如果设置为"错误",它将打印之前的警告并停止变基,然后可以使用 git rebase --edit-todo 来纠正错误。如果设置为"忽略",则不执行任何检查。要删除提交而不发出警告或错误,请使用待办事项列表中的删除命令。默认为"忽略"。

用提交哈希注释掉行与使用 DROP 关键字相同吗?

是的

我想重新调整我的拉取请求的基数,以便它只提交一次提交。

我假设您仍然希望保留所有更改,但将它们全部合并到一个大提交中。在这种情况下,您应该做的是将每个提交行开头的pick(第一个除外(更改为fixup

例如,假设您的变基提示如下所示:

pick b761975 Start a big project
pick 5239708 Oops fix a bug in the project
pick a85ecbe Oops fix another bug
pick 17a2131 Finally the big project is done

如果要将所有内容合并到一个标题为"启动一个大项目"的大提交中,请按如下方式对其进行编辑:

pick b761975 Start a big project
fixup 5239708 Oops fix a bug in the project
fixup a85ecbe Oops fix another bug
fixup 17a2131 Finally the big project is done

如果您还想更改大提交的提交消息,则可以将第一个pick更改为reword

是的。两者都是相同的(注释一行或删除关键字(。git 文档讲述了同样的事情。

有关更多信息,请参阅 Git 变基文档

要删除提交,请将命令"pick"替换为"drop",或者只是 删除匹配的行。

最新更新