Opening Files with Conflicts

After a merge, I would usually do git status to see which files have conflicts to be resolved. Then, I would manually open the files listed under unmerged paths one by one with Vim to edit them.

$ git status
On branch develop
Your branch is ahead of 'origin/develop' by 2 commits.
  (use "git push" to publish your local commits)

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

    both modified:   package.json
    both modified:   pages/main.js

no changes added to commit (use "git add" and/or "git commit -a")

Actually, we can get that list of files with git diff --name-only --diff-filter=U.

$ git diff --name-only --diff-filter=U
package.json
pages/main.js

To make it easier to edit all conflicted files, you can add a git alias in .gitconfig, so you can do git conflicts.

[alias]
    conflicts = !vim `git diff --name-only --diff-filter=U`

Alternatively, you can also use a shell alias, so you can do conflicts.

alias conflicts='vim $(git diff --name-only --diff-filter=U)'

Tags: git