Get out of the editor Git opened (and the log that won't quit)
git commit opened a text editor I can't get out of — how do I save and exit?
If you’re seeing this error
Aborting commit due to empty commit message.error: There was a problem with the editor 'vi'.hint: Waiting for your editor to close the file...You’re in the right place — the fix is below.
Short answer
You are in Vim. Press Esc, type :wq and press Enter to save and finish the commit, or :q! to abandon it. For a log or diff that has taken over the terminal you are in the pager instead — press q. Set git config --global core.editor "code --wait" (or nano) so it never happens again.
# In the editor: press Esc, then type
:wq # save and commit
:q! # quit without committing
# Stuck in git log or git diff output? Just press:
q
Esc then :wq for Vim, q for the pager
Does this match your situation?
- git commit with no -m opened a screen you cannot type into or leave.
- 'Aborting commit due to empty commit message.'
- git log fills the terminal and Ctrl+C does not return the prompt.
- 'hint: Waiting for your editor to close the file...' and nothing happens.
- An interactive rebase opened a list of commits and you cannot get out.
Step-by-step fix
Escape Vim: save or abandon
Vim starts in a mode where letters are commands rather than text. Esc guarantees you are in that mode, and the colon commands are how you leave. Saving a non-empty message completes the commit; quitting without saving aborts it and nothing is lost.
step 1# Save the message and complete the commit: Esc :wq Enter # Leave without committing: Esc :q! Enter # To type the message first: press i, type, then Esc :wqEscape the pager
git log, git diff and git show pipe their output through less. That is not an editor and nothing is waiting on you — q returns to the prompt immediately.
step 2q # quit the pager Space / b # page down / up /pattern # search, then n for next matchCtrl+C does not exit the pager; it only cancels a search. q is the key.
Change the editor to one you know
Vim is only the default because Git falls back to the system editor. Point core.editor anywhere you like — the --wait flag matters for GUI editors, because without it the program returns instantly and Git sees an empty message.
step 3git config --global core.editor "nano" git config --global core.editor "code --wait" git config --global core.editor "notepad" git config --global core.editor "'C:/Program Files/Sublime Text/subl.exe' -w"Skip the editor entirely
The editor only opens when Git needs a message and you have not supplied one. Passing -m avoids it for commits, and --no-edit accepts the existing message for amends and merges.
step 4git commit -m "Fix login redirect" git commit --amend --no-edit git merge --no-edit main git revert --no-edit <hash>Turn the pager off, or make it smarter
If you would rather output just printed and returned control, configure it. The -F -X combination is the pleasant middle ground: short output prints straight to the terminal and long output still scrolls.
step 5git config --global core.pager "less -F -X" git config --global pager.branch false git --no-pager log --oneline -10The editor never opened at all
'There was a problem with the editor' means Git could not run what core.editor names — usually a wrong path, a missing --wait, or a GUI editor invoked from a terminal that has no access to it. Check what Git is actually using.
step 6git var GIT_EDITOR git config --get core.editor echo "$GIT_EDITOR $VISUAL $EDITOR"
Why this works
Git never bundled an editor or a pager. When it needs prose from you it writes a template to .git/COMMIT_EDITMSG, runs whatever core.editor names, and waits for that process to exit — then reads the file back. That is why a GUI editor without --wait produces an empty commit message: the launcher process returns immediately, Git reads an untouched template, sees only comment lines, and aborts. The pager works the same way in the other direction, handing output to less rather than printing it, which is why q rather than Ctrl+C is what gets your prompt back. Both are ordinary external programs, so both are entirely yours to replace.
If that didn’t work
- If nothing responds, the terminal may be waiting on a different process — Ctrl+Z suspends it, then run kill %1.
- In the middle of an interactive rebase, :q! leaves the todo list empty and Git aborts the rebase safely.
- GIT_EDITOR=nano git commit sets the editor for one command without changing your config.
- On Windows, quote paths containing spaces and use forward slashes in core.editor.
How to stop it happening again
- Set core.editor to something you are comfortable in on every new machine.
- Always include --wait (or -w) for GUI editors, or every commit message will arrive empty.
- Use git commit -m for short messages and reserve the editor for ones worth writing properly.
- Learn just Esc :wq and q — those two cover nearly every stuck-in-Git-output moment.
Commands used in this guide
git configRead and write Git settings for one repo, your user, or the whole machine.
git commitRecord everything currently staged as a permanent snapshot.
git logBrowse commit history with as much or as little detail as you want.
git commit --amendReplace the most recent commit instead of stacking another one on top.
git rebase -iReorder, squash, split, reword or drop your recent commits.
Still stuck?
Search the full command reference and every other rescue guide — there are 76 of them, covering everything from detached HEAD to force-push disasters.
Browse all guides →Frequently asked questions
How do I exit Vim when Git opens it for a commit message?
Press Esc to leave insert mode, then type :wq and press Enter to save the message and complete the commit. Use :q! instead to quit without saving, which aborts the commit and changes nothing.
Why does Git say 'Aborting commit due to empty commit message'?
You closed the editor without writing anything above the commented lines, so Git had no message. With a GUI editor it usually means the --wait flag is missing: the editor returns immediately and Git reads the untouched template.
How do I change Git's default editor?
git config --global core.editor "nano", or "code --wait" for VS Code. The --wait flag is essential for GUI editors, because Git carries on the moment the process it launched exits.
How do I exit git log?
Press q. git log pipes through the less pager rather than an editor, so Ctrl+C will not return your prompt. Space pages down, b pages up, and /text searches.
Can I stop Git using a pager at all?
Yes — git config --global core.pager cat prints everything directly, and git --no-pager <command> does it once. A better middle ground is less -F -X, which prints short output straight to the terminal and still scrolls long output.
Related rescue guides
How do I edit a Git commit message?
For the most recent commit, git commit --amend -m "new message" replaces it. For older commits, git rebase -i lets you mark any of them as reword. Both rewrite history, so if the commit is already pushed you'll need git push --force-with-lease and a word to your team.
Read the fix →Always fixableHow do I combine multiple commits into a single commit?
git rebase -i HEAD~n opens an editor where you mark commits as squash or fixup to fold them into the one above. For a quick all-in-one collapse, git reset --soft HEAD~n followed by a fresh commit achieves the same result with no editor at all.
Read the fix →Always fixableMy pre-commit hook (or Husky) isn't running — why does Git ignore it?
Nine times out of ten the hook file is not executable, is misnamed, or sits in a folder Git isn't reading. Run git config core.hooksPath to see where Git actually looks, check the file is named exactly pre-commit with no extension, then chmod +x it. A stray global core.hooksPath silently overrides every repository on the machine — including Husky's.
Read the fix →Always fixablegit commit fails with 'error: gpg failed to sign the data' — how do I fix commit signing?
Test the signing outside Git first: echo test | gpg --clearsign. 'Inappropriate ioctl for device' means the passphrase prompt has nowhere to draw — add export GPG_TTY=$(tty) to your shell profile. 'No secret key' means user.signingkey does not match a key you hold. If you just want to commit right now, git commit --no-gpg-sign gets you through.
Read the fix →