Every thing you need to know to master git, Part 4, git merge, git diff with GUI tools

 

Before following this post, make sure you have already set up everything from my other post regarding the configuration of git environment.

Diff

Diff command will allow you to compare two different commits, let’s set up a repository:

Now in the second repository, we make some changes:

now let’s back to the first repository and see the changes:

now you should see all the difference in meld:

Merge and conflict

now let’s merge all the changes. If you make some changes on dii=fferent files you will do fast-forward. That means you only incorporate new changes and everything is ok afterward. But if you made some changes on the same file in same lines then you have a merge conflict and you should do a three-way merge.

To show you the point lets make some changes in the first repository in the file A.txt.

now if you call git merge, you will get a merge conflict, to solve this call the following:

and you will get this in meld:

and this in kdiff:

+————————————–+
| LOCAL | BASE | REMOTE |
+————————————–+
|                MERGED               |
+————————————–+

LOCAL: Your side of the conflict – ie, your branch (HEAD) that will contain the results of the merge
REMOTE: The remote side of the conflict – the branch you are merging into HEAD.
BASE: The common ancestor of both local and remote. useful for feeding into a three-way merge tool
MERGED: The result of the automatic merge.

go through the conflict and choose the side (A, B or C) and see the merged file in the window below and save and close.

Leave a Reply

avatar
  Subscribe  
Notify of