Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch
Solution 1
It's not a Git error message, it's the editor as git uses your default editor.
To solve this:
- press "i" (i for insert)
- write your merge message
- press "esc" (escape)
- write ":wq" (write & quit)
- then press enter
Solution 2
Actually it's not an error! It means you should enter some message to mark this merge.
My OS is Ubuntu 14.04
. If you use the same OS, you just need to do this as follows:
-
Type some message
-
CtrlCO
-
Type the file name (such as "Merge_feature01") and press Enter
-
CtrlX to exit
Now if you go to .git and you will find the file "Merge_feature01", that's the merge log actually.
Solution 3
tl;dr ✨ Use an $EDITOR that you like! ✨
The fix is not to memorize cryptic commands, like in the accepted answer, but configuring Git to use an editor that you like and understand!
The underlying problem is that Git by default uses an editor that is too unintuitive to use for most people: Vim. This is because Vim is present everywhere, not because it is user friendly 😄 Now, don't get me wrong, I ❤️ Vim, and while you could set some time aside to learn Vim and try to understand why some people think Vim is the greatest editor in existence, there is a quicker way of fixing this problem :-)
It's really as simple as configuring either of these options
- the git config setting
core.editor
(per project, or globally) - the
VISUAL
orEDITOR
environment variable (this works for other programs as well). Typically stuffingexport VISUAL="vscode --wait"
into your.bashrc
or similar config.
I'll cover the first option for a couple of popular editors, but GitHub has an excellent guide on this for many editors as well.
🔥 To use Atom
Straight from its docs, enter this in a terminal:
git config --global core.editor "atom --wait"
Git normally wait for the editor command to finish before progressing, but since Atom forks to a background process immediately, this won't work, unless you give it the --wait
option. This makes it stay as a foreground process, just as we want.
🦄 To use Sublime Text
For the same reasons as in the Atom case, you need a special flag to signal to the process that it shouldn't fork to the background:
git config --global core.editor "subl -n -w"
🤓 To use Visual Studio Code
git config --global core.editor "code --wait"
Solution 4
Just Do,
CTRL + X
CTRL + C
It will ask you to save file, Press Y, then you are done.
Solution 5
Instead, you could git CtrlZ and retry the commit but this time add " -m " with a message in quotes after it, then it will commit without prompting you with that page.
bernie2436
Updated on July 08, 2022Comments
-
bernie2436 almost 2 years
I am using Git. I did a pull from a remote repo and got an error message:
Please enter a commit message to explain why this merge is necessary,
especially if it merges an updated upstream into a topic branch.I try to type a message and press Enter but nothing happens.
How do I tell Git/Terminal I am done typing in my message?
I am using Terminal on OS X.
-
Gabriele Petronella over 10 yearsOk, but this is assuming his editor is
vi
orvim
. -
Connor Leech over 9 yearsthat's hella complicated
-
Ans about 9 yearsI'm using Terminal for on Mac (Yosemite) and this solution worked for me.
-
Josh Beam almost 9 yearsIf it helps anyone, the way you remember this is that "i" is for "insert", "esc" is the exit the insertion, and ":wq" is just "write" and "quit".
-
Adrian Carr over 8 yearsI wonder how someone would know this? It's so strange how this works. Thanks for answering this.
-
abbas over 8 yearsTo make life easier just follow step-4: write ":wq" then press enter
-
joshmcode over 7 years@JoshBeam ahhh, maybe now (following your memory suggestion) I can finally stop coming to this answer repeatedly!
-
Arno over 7 yearsI'm seeing the same issue. Commit and push from box A, pull from box B Box B says that includes a merge so I include the message like in the answer above. Once I do so "git status" after that B says I'm ahead by 1 commit so the process repeats. I have to push from box B even though "git diff" shows there are no differences to be able to do a subsequent pull.
-
mfaani over 7 years@Wooble Why did this happen in the first place? I just did
git merge master
as always... -
Cozzbie over 7 yearsThis answer is still relevant till this moment.
-
Wesley Smith over 7 yearsThis might as well be ↑↑↓↓←→←→BA
-
David Douglas about 7 yearsOr ":x" to eXit
-
Luke Smith about 7 years'Enter :wq'. This is without the doubt the single least intuitive thing that has ever been designed by anyone ever. How on earth would anyone work out how to do that??!!!!! Jeeezzzz
-
Ashraf Slamang over 6 yearsTo switch the default editor for git to
nano
run this command:git config --global core.editor "nano"
-
oligofren over 6 years@ScottyBlades why on earth should it? the question is tagged osx, and this answer concerns how Ubuntu sets up an entirely different setup for Git (using
nano
orpico
), which is not applicable to the OS X setup. It is in no way generalizable and also doesn't provide insight into how it works, hence the comment left by @AdrianCarr. There are far better answers now. -
James M. Lay over 6 yearslol this would definitely solve the OP's problem.
git commit -m 'I did blah'
-
Ram about 6 yearsCould you please explain these 2 steps :- 1. press "i" 2. press "esc" 3. write ":wq" What is the meaning of these shortcuts.
-
Ram about 6 years@Saad.elzwawy Working fine. But could you please explain each steps meaning. I just want to know in details.
-
Saad.elzwawy about 6 yearsHi, @Ram press "i" i: Insert to insert text message for your commit, press "esc" esc: escape after finish write mode, and wanna go out, write ":wq" wq: write-quite it write and save your message then quite vim, then press enter
-
TMOTTM almost 6 yearsWhy is this appearing suddendly? I didn't have it on the last 10 commits.
-
Saad.elzwawy almost 6 years@TMOTTM this happen when you merge with another branch, for example: suppose your current branch name is xx, and you want to merge it with yy, then your write : git pull origin yy ..... in this message will appear.
-
pglpm almost 6 yearsI have git version 1.7.11.4 on a linux terminal, and despite the fact that I give git commit -m "message" or git commit --message "message", still the editor pop ups from time to time, requesting a message. Does anybody knows why the "-m" switch is ignored?
-
user264431 almost 5 yearsVim doesn't take a month. it takes two days and you never forget as long as you keep a handy cheat sheet you'll need from time to time, at first.
-
oligofren almost 5 years@hipoglucido There is nothing that says you have to have to use Vim! Just configure Git to use a different editor; one you like. See my answer for how.
-
JacKeown over 4 yearsThis is if your default editor is "pico" or "nano" The above comments should be used if your default editor is vim.
-
Henry Thomas almost 4 yearsYou literally have to enter the launch codes just to commit... you should just be able to press enter and be done.
-
J. Mini almost 4 yearsWhat is the name of the editor that corresponds to this answer?
-
mate00 almost 4 yearsIs this really a helpful answer after over 6 years?...
-
Vladimir almost 4 yearsI think so, because i because I ran into these yesterday
-
tripleee almost 4 yearsIt looks vaguely like this assumes your editor is
nano
. It has an obnoxious bar across the bottom which tells you some of the keyboard shortcuts. -
Eldrax over 3 yearsFor everyone confused: this sequence has nothing to do with Git. Git sometimes has to ask you for a commit message (try
git commit
without providing a message, and the same should happen), and it does so by opening the text editor set in Git as default. On Linux-based OSes, this is generally Vim: a text editor that focuses on doing stuff with minimal keystrokes. The instructions in this answer are keystrokes for writing the message, saving and exiting the editor. Agreed, it looks weird if you've never used Vim, but this weird-looking sequence really has nothing to do with Git. -
Josh about 3 years@WesleySmith I though so, this is like executing a Fatality on MK 2 in the 90s, except one wrong key, and the fatality end up on ourselves. Nevertheless this worked fine for me in Android Studio Terminal for Mac.
-
Gringo Suave almost 3 yearsUse a CUA terminal editor like micro: micro-editor.github.io
-
oligofren almost 3 yearsThis is superfluous and covered by the accepted answer.
-
oligofren almost 3 yearsThis has nothing to do with this issue directly: "How do I tell Git/Terminal I am done typing in my message?". The user needs to set his editor in the global git config or set the EDITOR variable.
-
Alessandro Sassi almost 3 yearswrite ":wq" means that when you type ":" it starts typing in the lower line, there you will type "wq". it was not obvious for me
-
John Miller almost 3 yearsCan someone please explain why git is using vim at all? Are we going to be stuck in the stone ages for forever or are we going to replace these old, clunky designs with better, more intuitive systems?
-
oligofren over 2 years@JohnMiller That's not hard to answer at all. Git does not care what editor you use, but it needs to use something. What editor is present in every operating system you can think of? The ubuquitous answer on Unix-like operating systems is
vi
. Neither nano, micro, pico or emacs can say that. And a GUI editor would be a no go. That's why every programmer should know the basics. And since this is dead easy to configure for the user to use something else, it's much better to consult the user's preferences than to think of complicated per-operating system rules.