在 Git 中变基时,COMMIT 会丢失什么?
What does COMMIT WILL BE LOST when rebasing in 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 关键字相同?
我想重新设置我的 Pull Request 的基数,以便它只提交一个提交。
是的,drop
和删除的行都将导致删除提交。来自 the docs:
To drop a commit, replace the command "pick" with "drop", or just delete the matching line
但也有细微差别。例如:
- 删除所有行将中止变基,因此这与 drop all
不同
- 当缺少行时,可以对 warn/error 启用检查:
rebase.missingCommitsCheck:
If set to "warn", git rebase -i will print a warning if some commits are removed (e.g. a line was deleted), however the rebase will still proceed. If set to "error", it will print the previous warning and stop the rebase, git rebase --edit-todo can then be used to correct the error. If set to "ignore", no checking is done. To drop a commit without warning or error, use the drop command in the todo list. Defaults to "ignore".
Is commenting out the line with the commit hash the same as using the DROP keyword?
是
I'd like to rebase my Pull Request so it only has one commit submitted.
我假设您仍想保留所有更改,但将它们全部合并到一个大提交中。在这种情况下,您应该做的是将每个提交行(除了第一个提交行)开头的 pick
更改为 fixup
.
例如,假设您的 rebase 提示如下所示:
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
如果你想将所有这些合并到一个名为 "Start a big project" 的大提交中,请按如下方式编辑它:
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 rebase documentation
To drop a commit, replace the command "pick" with "drop", or just
delete the matching line.
#
# 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 关键字相同?
我想重新设置我的 Pull Request 的基数,以便它只提交一个提交。
是的,drop
和删除的行都将导致删除提交。来自 the docs:
To drop a commit, replace the command "pick" with "drop", or just delete the matching line
但也有细微差别。例如:
- 删除所有行将中止变基,因此这与 drop all 不同
- 当缺少行时,可以对 warn/error 启用检查:
rebase.missingCommitsCheck: If set to "warn", git rebase -i will print a warning if some commits are removed (e.g. a line was deleted), however the rebase will still proceed. If set to "error", it will print the previous warning and stop the rebase, git rebase --edit-todo can then be used to correct the error. If set to "ignore", no checking is done. To drop a commit without warning or error, use the drop command in the todo list. Defaults to "ignore".
Is commenting out the line with the commit hash the same as using the DROP keyword?
是
I'd like to rebase my Pull Request so it only has one commit submitted.
我假设您仍想保留所有更改,但将它们全部合并到一个大提交中。在这种情况下,您应该做的是将每个提交行(除了第一个提交行)开头的 pick
更改为 fixup
.
例如,假设您的 rebase 提示如下所示:
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
如果你想将所有这些合并到一个名为 "Start a big project" 的大提交中,请按如下方式编辑它:
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 rebase documentation
To drop a commit, replace the command "pick" with "drop", or just delete the matching line.