Git rebase --continue without opening the editor
Asked Answered
H

1

10

When invoking git rebase --continue after a normal rebase conflict, the editor (GIT_EDITOR) opens and asks for modifying the commit message. Because commit messages may contain leading # this might fail.

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

In the Git rebase documentation there is following paragraph

Commit Rewording When a conflict occurs while rebasing, rebase stops and asks the user to resolve. Since the user may need to make notable changes while resolving conflicts, after conflicts are resolved and the user has run git rebase --continue, the rebase should open an editor and ask the user to update the commit message. The merge backend does this, while the apply backend blindly applies the original commit message.

So I tried to switch to the apply backend, but it still fails:

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

How to force Git to blindly apply the commit message?

Hilliary answered 9/10, 2020 at 8:50 Comment(3)
You probably want to pick another character for the comment if you actually want to use # in the commit messages. But I'd argue that it's a risky proposition anyway. See this question. core.commentChar=auto might just help you.Socalled
You cannot switch the back-end rebase program in the middle of the rebase: it's chosen at the start of the rebase operation, and from then on, git rebase --continue continues that particular back-end. However, the GIT_EDITOR=true trick should work and I'm not sure why it did not.Acrilan
@JoachimSauer Unfortunately, git -c core.commentChar=auto rebase <commit> <branch> has exactly the same problem. git -c rebase.backend=apply rebase <commit> <branch> works, but I wonder whether it has some negative consequences. There surely is a reason why git defaults to merge and not apply.Hilliary
H
4

A workaround I've found, is specifying the core.commentChar detected from the .git/rebase-merge/message (here @):

git -c core.commentChar=@ rebase --continue
Hilliary answered 14/10, 2020 at 9:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.