-
Notifications
You must be signed in to change notification settings - Fork 1
Merge branches
Before trying to resolve conflict let's look at how to merge branches.
You need to merge branches when you are done with experimenting and want to merge your experimental work with the master branch that everybody uses, the stable version of your code.
ben@GregoryHouse:~/tmp/testRepo-clone (master)$ cd ../testRepo-
From here run gitk and check what branches are at which commit. (so much more convenient than the command line in this case).
-
master should be behind experimental. Let's say experimental is mature enough, let's merge it with the master.
ben@GregoryHouse:~/tmp/testRepo (master)$ git merge experimental
Updating c6c5566..c3df0e6
Fast-forward
README | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)-
Easy, just a simple fast forward.
-
Sometimes things are a bit more complicated. the master has advanced and the experimental advanced as well but without following the development of the master.
-
to simulate this, add a new commit on the README file of the master branch, commit it, then checkout the experimental branch, and commit an other change in README. Commit and try a merge from master:
ben@GregoryHouse:~/tmp/testRepo (master)$ vi README
ben@GregoryHouse:~/tmp/testRepo (master *)$ git commit -a -m "Beautifying"
[master 6ac62bc] Beautifying
1 file changed, 2 insertions(+), 2 deletions(-)
ben@GregoryHouse:~/tmp/testRepo (master)$ git checkout experimental
Switched to branch 'experimental'
ben@GregoryHouse:~/tmp/testRepo (experimental)$ vi README
ben@GregoryHouse:~/tmp/testRepo (experimental *)$ git commit -a -m "it will clash"
[experimental 79f82eb] it will clash
1 file changed, 1 insertion(+), 1 deletion(-)- Let's try the merge. There are two cases:
- The changes you made didn't touch the same lines: the merge will be automatic
- The changes touched the same lines in the file there is a conflict
ben@GregoryHouse:~/tmp/testRepo (experimental)$ git merge master
Auto-merging README
CONFLICT (content): Merge conflict in README
Automatic merge failed; fix conflicts and then commit the result.Jump to Resolve Conflicts