【问题标题】:What does COMMIT WILL BE LOST when rebasing in Git?在 Git 中变基时 COMMIT 会丢失什么?
【发布时间】:2020-03-22 13:14:12
【问题描述】:
#
# 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 关键字相同吗?
我想重新设置我的拉取请求,以便它只提交一个提交。

【问题讨论】:

    标签: git github rebase git-commit git-interactive-rebase


    【解决方案1】:

    是的。两者都是相同的(评论一行或删除关键字)。 git 文档告诉了同样的事情。

    更多信息,请参考git rebase documentation

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

    【讨论】:

      【解决方案2】:

      是的,drop 和删除的行都将导致删除提交。来自the docs

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

      但也有细微的差别。例如:

      1. 删除所有行将中止 rebase,因此这与 drop all 不同
      2. 有一个检查可以在缺少行时启用警告/错误:

        rebase.missingCommitsCheck: 如果设置为“警告”,如果某些提交被删除(例如,删除了一行), git rebase -i 将打印一个警告,但是 rebase 仍将继续。如果设置为“error”,它将打印之前的警告并停止 rebase,然后可以使用 git rebase --edit-todo 来纠正错误。如果设置为“忽略”,则不进行检查。要在没有警告或错误的情况下删除提交,请使用待办事项列表中的 drop 命令。默认为“忽略”。

      【讨论】:

        【解决方案3】:

        使用提交哈希注释掉行与使用 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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-04-03
          • 1970-01-01
          • 2011-07-07
          • 2014-10-19
          • 2018-02-14
          • 2018-05-30
          • 2019-12-12
          • 2014-08-23
          相关资源
          最近更新 更多