【问题标题】:Git rebase --continue without opening the editorgit rebase --continue 不打开编辑器
【发布时间】:2021-01-24 08:12:10
【问题描述】:

在正常的 rebase 冲突后调用 git rebase --continue 时,编辑器 (GIT_EDITOR) 打开并要求修改提交消息。因为提交消息可能包含前导 # 这可能会失败。

$ export GIT_EDITOR=true
$ git rebase --continue
Aborting commit due to empty commit message.
error: could not commit staged changes.

Git rebase documentation 中有以下段落

提交改写 当 rebase 发生冲突时,rebase 会停止并要求用户解决。由于用户在解决冲突时可能需要进行显着更改,因此在解决冲突并且用户运行 git rebase --continue 后,rebase 应该打开一个编辑器并要求用户更新提交消息。合并后端执行此操作,而应用后端盲目地应用原始提交消息

于是我尝试切换到apply后端,但还是失败了:

$ export GIT_EDITOR=true
$ git config rebase.backend apply
$ $ git config --list | grep backend
rebase.backend=apply
$ git rebase --continue
Aborting commit due to empty commit message.
error: could not commit staged changes.

如何强制 Git 盲目应用提交消息?

【问题讨论】:

  • 如果你真的想在提交消息中使用#,你可能想为评论选择另一个字符。但我认为无论如何这都是一个冒险的提议。见this questioncore.commentChar=auto 可能会对您有所帮助。
  • 你不能在rebase中间切换后端rebase程序:它是在rebase操作开始时选择的,从那时起,git rebase --continue继续那个特定的后端。但是,GIT_EDITOR=true 技巧应该有效,但我不确定为什么无效。
  • @JoachimSauer 不幸的是,git -c core.commentChar=auto rebase <commit> <branch> 有完全相同的问题。 git -c rebase.backend=apply rebase <commit> <branch> 有效,但我想知道它是否会产生一些负面影响。 git 默认合并而不应用肯定是有原因的。

标签: git


【解决方案1】:

我发现的一种解决方法是指定从.git/rebase-merge/message 检测到的core.commentChar(此处为@):

git -c core.commentChar=@ rebase --continue

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-19
    • 2015-04-24
    • 2014-03-20
    • 2017-09-25
    • 1970-01-01
    • 2013-06-26
    • 1970-01-01
    • 2014-03-27
    相关资源
    最近更新 更多