SteGriff

Blog

Next & Previous

Resolving merge conflicts in git bash - some tips

Visual Studio’s libgit2 integration is really slow on my work PC, so when I need to bulk-resolve some merge conflicts, git bash is faster.

These are some tips for a limited set of situations…

Deleted by them

I had gitignored and git rm‘d some generated XML files, and that change got merged to main. When merging back to another feature branch, it looks like:

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
        deleted by them: Src/ACME.Business/App_Data/ACME.Business.xml
        deleted by them: Src/ACME.Public.DocumentService/App_Data/ACME.Business.xml
        (+ 4 more)

The tip given by git here is right; use git rm… but we can make it faster with a wildcard to match multiple files:

git rm *.Business.xml

That will “accept the delete” and remove those files from the conflict list.

Both modified - keep ours/theirs

File modified on both sides, but you just want to keep your whole file or theirs?

Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   Src/ACME.Core/Properties/AssemblyVersion.cs

Use git checkout --theirs <file> on a pathspec to keep theirs during a merge. Does what it says on the 🥫!

Likewise to keep yours, use --ours (apparently you could also use git checkout HEAD <file>)

You have to git add the change afterwards, or it continues to show as “both modified”.

Anything else

For line-by-line changes, you will need to use a text editor. GitHub have some general advice on resolving a merge conflict using the command line which is a shallow overview. Use your editor’s features! 🕵️‍♀️

Đây là ngày cuối cùng làm viẹc của anh, năm nay. Chúc mừng giáng sinh! 🎄⛪