Why is git prompting me for a post-pull merge commit message?
Asked Answered
B

3

162

Recently, following any git pull, git has started spawning my text editor, and asking for a merge commit message. A commit message is already pre-filled, and I just have to save and close the window to complete the pull.

In the past, it would do the merge silently, with a standard commit message (along the lines of Merge branch 'dev' of remote.com:/repo into dev).

I recently updated git to version 1.7.11.3 (via homebrew), but can't think of anything else I might have done to change this behavior. Is this a setting, or is there otherwise some way of getting back to the way it was?

Bumblebee answered 31/7, 2012 at 15:50 Comment(0)
S
174

In git 1.7.10, the git developers decided merge commits could be made too easily. As explained in this blog post, forcing the interactive commit message behavior should make those commit messages more detailed and could reduce the overall frequency of unnecessary merges.

You can use the --no-edit flag to avoid this behavior, but, well, don't. Merge commits, like any commits to history, should be well constructed. Your history should be nothing but useful.

Stereochromy answered 31/7, 2012 at 16:10 Comment(12)
Thanks for the help. I disagree that merge commits should always be descriptive though. The reason I looked this up is because automatic merges whenever I pull are asking me to explain why the merge is necessary, which quickly becomes unreasonable since it's even doing that when I don't have any changes.Piety
This is also a useful resource for avoiding this behavior: longair.net/blog/2009/04/16/git-fetch-and-merge You should be avoiding git pull; use git merge --ff-only if you are just trying to update and you don't think you have any local changes; use git merge --no-ff if you are actually trying to merge a branch in.Formalin
Is there a config flag to turn this off? It's annoying to have to type --no-edit every time.Reims
While we're at it- opposite question, I'm using an older Git version (1.7.0.4) on one machine, can I set 1.7.10's behaviour as the default?Moorman
@Kos: Hmmm. Try git merge's --no-ff flag. That'll force a merge commit with every merge, which might get you what you want. You can then "make it permanent" by setting git config --global merge.ff false. man git-config should get you more details. I've no easy way to regress to v1.7.0.4 on this machine and thus can't test this suggestion.Stereochromy
I always pull with --ff-only and normally only merge when I want --no-ff, but I asked about a setting "ask for a commit message before every merge".Moorman
@Kos: Ah, unfortunately I'm not sure of a way to get what you want in 1.7.0.4. Someone else might though. It'd make a decent SO question on its own.Stereochromy
How do I edit the text and dismiss this edit window on a mac terminal session. Seems whatever I do I have to quit out and re-do the commit manually.Ensign
@SeanCoetzee: It depends on your $EDITOR setting, but if you're using git out of the box on OSX it's probably a program called 'vi'. Type i to enter "INSERT" mode; type your message. You can then save and quit by hitting ESC and then typing :wq.Stereochromy
If your git merge command is in a script for automation, consider using git merge -m flag to supply useful information for the commit logs.Coltoncoltsfoot
You're correct as to why, but the admonishing to keep putting up with this annoyance is unhelpful - downvoted for that. I'll switch it to an upvote if you remove the brow-beating.Synchroscope
Just a note: --no-edit belongs right after pull keyword, like this: git pull --no-edit update master. Lost an hour figuring why it does not work.Mcfall
T
71

To create a shortcut for future use, either:-

Edit your ~/.gitconfig with the following:

[core]
    mergeoptions = --no-edit

Or execute the following in Terminal

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

Terrill answered 14/12, 2014 at 18:34 Comment(5)
This didn't work for me (git on OSX), and I've set it correctly, looking at the output of git config --global core.mergeoptions.Nonie
terminal command should be like below git config core.mergeoptions --no-editJillayne
@SimsekMert that will only edit the .gitconfig in the current respository, not globally for every git repositoryTerrill
@AbhishekGoel there's a chance you may need to restart Terminal for the changes to take affectTerrill
@jvannistelrooy there's a chance you may need to restart Terminal for the changes to take affectTerrill
C
14

First, take heed of the warnings in Christopher's answer above.

Then, if you still want to disable automatic merge commit message editing, set this environment variable:

    GIT_MERGE_AUTOEDIT=no

This environment variable and its "no" setting are documented on the git merge doc page. It is recommended to use it only in scripts that need to merge non-interactively, but of course it can be set as part of your shell environment to make its effects more permanent.

Clang answered 27/1, 2017 at 22:11 Comment(2)
Can you explain how this might be different than using the --no-edit flag?Glad
I don't know of a functional difference, but the convenience factor makes it worthwhile. The --no-edit flag has to be repeated on the command line with each usage, as it does not appear to work in the settings as described in Dallas Clark's answer here. Setting the environment variable is the only way I know to make this setting stick.Clang

© 2022 - 2024 — McMap. All rights reserved.