Jeroen Haegebaert

To content | To menu | To search

Tuesday 26 August 2008

Resolving merge conflicts with git and kdiff3

A little bit confusing to get started, but in the end quite simple. To get started, the easiest is to put the kdiff3 folder in your path.

Assume you're on branch 'master' and want to merge changes from 'master' to 'working'

C:\Projects\GitTest>git checkout working
C:\Projects\GitTest>git merge master
Auto-merged blabla.txt
CONFLICT (content): Merge conflict in blabla.txt
Automatic merge failed; fix conflicts and then commit the result.

To fix the conflicts using kdiff3, first you need to tweak the kdiff3 configuration a bit: start kdiff3, and go to Settings, Configure KDiff3, Integration. Under 'Command line options to ignore', add ';--'. To resolve conflicts, you can now use:

git mergetool -t kdiff3

To permanently configure kdiff3 as the merge tool (so you don't need to specify the '-t kdiff3' anymore):

git config merge.tool kdiff3

Thursday 24 July 2008

Getting started with Git

Today I got fed up with some of the quirks of TFS, and decided to try git, to see whether I could set it up so that I would be developing under git, setting up a water-proof system integrating with TFS some way or another.

Here's how to get started with git on windows:

  • Installing git: just run the windows installer from The installer lets you choose whether to add Git to the PATH environment variable (so git is available in the Windows command prompt). You can also opt to exclusively use the BASH shell that comes with the installer.
  • Configuring Git: at the command prompt, type the following commands:
      git config --global "Your Name Here"
      git config --global "YourEmail@YourDomain"
  • Importing code:
      git init
      git add *
      git commit -m "initial commit"

For actually synchronizing TFS with git, I think the following scheme may work, but I'm not entirely satisfied with it yet. For now, I created just one branch, 'working' (using 'git branch working'). I'm synchronizing my git environment with TFS as follows:

  • in TFS, do a 'get latest version'
  • in git, make sure everything is committed in branch 'working' + switch the 'git' working copy to 'master' (using 'git checkout master')
  • sync the TFS working copy to the git working copy (I'm using robocopy for this)
  • commit the TFS changes the 'master' branch (git commit -a -m "get latest version from TFS")

Then, I merge my own changes from 'working' to 'master' (git merge working) and still need to synchronize everything back to TFS.

For this I need to

  • check out all files changed by the merge (working -> master)
  • copy all changed files from git -> tfs working copy
  • check in in TFS

I'm not yet entirely satisfied with this scheme (I don't really like the 'robocopy' steps), but I'm not sure if there is a better way at this point...