Skip to content

Instantly share code, notes, and snippets.

@jacobvosmaer
Created July 27, 2012 10:35
Show Gist options
  • Save jacobvosmaer/3187346 to your computer and use it in GitHub Desktop.
Save jacobvosmaer/3187346 to your computer and use it in GitHub Desktop.
Open all files with git merge conflicts in Vim

Open all files with git merge conflicts in MacVim

git diff --name-only | uniq | xargs mvim

When git encounters a merge conflict, e.g. during a rebase, it drops you back into the shell with a dirty working directory. I like this one-liner for opening all files with a merge conflict in MacVim.

Once you're in Vim, you can then switch between the files with :n and :prev, or another favourite: :w | n (save current file and open the next command line-supplied file).

UPDATE: see below for a version that works with real terminal commands.

@Westacular
Copy link

All of the above solutions choke on paths with spaces in them. The solution for that is to use -z for git diff to output raw null-terminated strings, and xargs -0 to pass them to $EDITOR:

git config --global alias.fix '!git diff --name-only --relative -z --diff-filter=U | xargs -0 ${EDITOR}'

@kernhanda
Copy link

this works for me on linux and in a terminal

git config --global alias.fix '!${EDITOR} $(git diff --name-only --relative --diff-filter=U | uniq)'

@dpapp-hortonworks
Copy link

Using the original command somehow messes with my terminal when I exit vim. For me the following works better:

vim -p `git diff --name-only | uniq`

@krisleech
Copy link

vim `git diff --name-only --diff-filter=U  | uniq` 

Copy link

ghost commented Nov 16, 2019

alias fix='vim +/HEAD `git diff --name-only | uniq`'

will open vim with the cursor at the first merge conflict.

@iFrostizz
Copy link

wrote a vim-compatible plugin that does that within vim ! https://github.com/iFrostizz/vim-conflict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment