ChatGPT解决这个技术问题 Extra ChatGPT

Git merge doesn't use default merge message, opens editor with default message

How can I force git merge to use the default merge message instead of loading my editor with said message?

I have no editor listed in git config -l, so I'm not sure why it opens an editor.

Not sure, but doesn't merge - as commit - have the option --no-edit?

k
kjb

Found the answer after some digging

EDIT: As per Mark's suggestion, this is the best way to do so:

git config --global core.mergeoptions --no-edit

Rather than edit ~/.gitconfig directly, it might be safer to suggest using git config to do this, e.g. git config --global core.mergeoptions --no-edit, so that there's no chance of creating a malformed ~/.gitconfig.
This seems to work for git merge's, but I'm still having an editor open up for git pull's. Is there any way to disable the commit message for this as well?
I can't find any mention of core.mergeoptions, though it certainly applies to branch.*.mergeoptions. Does anyone know the supported versions for this?
This doesn't work for me. Both merge and pull still bring up an editor on non-ff merges. Using git 1.7.10.4
A trip through the git source and release notes suggests that there is not now and never was a core.mergeoptions. There is, however, a GIT_MERGE_AUTOEDIT=no that was added to git 1.7.10 when git merge itself was changed to bring up the editor. There are also options available as branch.*.mergeoptions, as @cmbuckley noted.
o
ouah

Use

export GIT_MERGE_AUTOEDIT=no

or

git merge --no-edit

This is almost what I wanted, but it forces you to type --no-edit every time. The solution I found changes the default behavior of git merge
Passing it directly to the merge command, as suggested here, is specially useful in a script that invokes git merge. You almost always want a script not to prompt the user. However, it'd be nice to know how to pass a custom message to git merge. Perhaps git merge -m "message" works but I haven't tried it yet.
For me, export GIT_MERGE_AUTOEDIT=no worked (for merges) when the accepted answer (git config --global core.mergeoptions --no-edit) did not.
O
Orlando

This is a new feature of Git, introduced in Git 1.7.10, to use the old one (don't provide a message on merge) put these two lines in your .bash_profile or .bashrc

GIT_MERGE_AUTOEDIT=no
export GIT_MERGE_AUTOEDIT

d
dawn360

try this

git merge --no-ff --no-edit -m "my custom merge message" somebranch