lab 15 Resolving Conflicts
Goals
- Learn how to handle conflicts during a merge
Merge master to greet 01
Now go back to the greet branch and try to merge the new master.
Execute:
git checkout greet git merge master
Output:
$ git checkout greet Switched to branch 'greet' $ git merge master Auto-merging hello.c CONFLICT (content): Merge conflict in hello.c Automatic merge failed; fix conflicts and then commit the result.
If you open hello.c, you will see:
File: hello.c
#include#include "greeter.h" int main(int argc, char *argv[]) { if (argc > 1) { greet(argv[1]); } else { <<<<<<< HEAD greet("World"); ======= char name[100]; printf("Enter your name> "); scanf("%s",name); printf("Hello %s!\n",name); >>>>>>> master } return 0; }
The first section is the version on the head of the current branch (greet). The second section is the version on the master branch.
Fix the Conflict 02
You need to manually resolve the conflict. Modify hello.c
to be the following.
File: hello.c
#include <stdio.h> #include "greeter.h" int main(int argc, char *argv[]) { if (argc > 1) { greet(argv[1]); } else { char name[100]; printf("Enter your name> "); scanf("%s",name); greet(name); } return 0; }
Commit the Conflict Resolution 03
Execute:
git add hello.c git commit -m "Merged master fixed conflict."
Output:
$ git add hello.c $ git commit -m "Merged master fixed conflict." Recorded resolution for 'hello.c'. [greet 25f0e8c] Merged master fixed conflict.
Before going on with next lab, let's get back to the master branch.
Execute:
git checkout master
Output:
$ git checkout master Switched to branch 'master' $