Home > other >  I ran `git merge` and got this screen: what editor is this
I ran `git merge` and got this screen: what editor is this

Time:07-19

enter image description here

I tried to merge some changes from my branch to the main, but everytime that I make git merge Diego2, gitbash send this screen IDK what to do

CodePudding user response:

This is an vi editor window. This is happening because git cannot perform a fast forward and is prompting you for a message for a merge commit. Vi has a bit of a learning curve and can be confusing for new users.

First, I'd like to mention that you can change what this editor is via the core.editor gitconfig setting. I've included the docs for that below, which describe how to change the editor to emacs (another text editor):

core.editor By default, Git uses whatever you’ve set as your default text editor via one of the shell environment variables VISUAL or EDITOR, or else falls back to the vi editor to create and edit your commit and tag messages. To change that default to something else, you can use the core.editor setting:

git config --global core.editor emacs

You can find a list of editor configs here. For other editors, you might have to do some tinkering or googling.

Secondly, I'd like to provide the basics on how to use vi and how commit messages are formatted. Regarding commit messages, the first line is the subject line. An optional body can be added to provide greater detail. It is below the subject line and is separated from it via a blank line.

Vi consists of several, but primarily three modes, NORMAL, INSERT and VISUAL. When first opening vi, you're in NORMAL mode, which is primarily used for navigation. You can begin typing once you enter INSERT mode, and you can select text to be cut or copied in VISUAL mode. Here are some key keybindings:

  • i enters INSERT mode at the current position
  • Esc lets you return to NORMAL mode from INSERT/VISUAL mode
  • h lets you move left in NORMAL mode
  • j lets you move down in NORMAL mode
  • k lets you move up in NORMAL mode
  • l lets you move right in NORMAL mode
  • u lets you undo changes while in NORMAL mode
  • C-r / Ctrl r lets you redo changes while in NORMAL mode
  • :wq while in NORMAL mode will write and quit the editor. Doing this allows you to continue with the merge, once you're satisfied with the message.
  • :cq while in NORMAL mode will quit vim and throw a compiler error. I find this useful if I want to inspect an interactive rebase without actually doing it. NOTE: if you do this while merging you'll end up in the MERGING git state. You'd have to use git merge --continue to continue the merge or git merge --abort to abort the merge.

EDIT: The format of a commit message is:

Subject line 

body text 

Here's a commit message example as well:

    Merge branch 'jc/revert-show-parent-info'

    * jc/revert-show-parent-info:
      revert: config documentation fixes

In this example, the line beginning with Merge branch is the subject line and the line beginning with the asterisk is the start of the body.

For the window you posted, the subject would be: Merge remote-tracking branch 'origin/Diego2' and it will not contain a body. This is perfectly fine unless you want to add more detail about what's introduced by the merge. If you're satisfied with the current message, press Esc to ensure you're in NORMAL mode followed by :wq to save and quit vi.

  • Related