Git
Conflict case
Learn to resolve a conflict during cherry-pick.
What is a conflict?
If two commits changed the same line, cherry-pick cannot know which version should win; this is called a conflict. Marks like <<<<<<< put the two versions side by side in the file, and the operation waits.
<<<<<<< HEAD
v3
=======
v2
>>>>>>> surum
Now it is your turn to decide.
Resolve and continue
To resolve the conflict you edit the file, keep the content you want and delete the extra marks. Then you mark the file with git add and finish the operation with git cherry-pick --continue.
git add dosya.txt
git cherry-pick --continue
The operation ends this way and the commit is created.
Exercise Resolve the conflict and continue
Create dosya.txt with v1 inside, add it and save quietly. Open a branch named surum; set the content to v2 and save quietly, then go back to the previous branch, set it to v3 and save quietly. Try to take the commit from the surum branch with git cherry-pick; when the conflict appears resolve the file as v2, add it again and finish with --continue. Print the contents of dosya.txt at the end.
Show example solution
git init -q
echo v1 > dosya.txt
git add dosya.txt
git commit -q -m "v1"
git checkout -q -b surum
echo v2 > dosya.txt
git add dosya.txt
git commit -q -m "v2"
git checkout -q -
echo v3 > dosya.txt
git add dosya.txt
git commit -q -m "v3"
git cherry-pick surum >/dev/null 2>&1 || true
echo v2 > dosya.txt
git add dosya.txt
GIT_EDITOR=true git cherry-pick --continue >/dev/null 2>&1
cat dosya.txt
Test yourself
-
What happens when a conflict appears during cherry-pick?
- Git always chooses the version from the source commit
- The changes are skipped silently and no commit is made
- The branch is deleted automatically
- Conflict markers stay in the file and the operation waits
Show answer
Conflict markers stay in the file and the operation waits — When a conflict appears Git cannot decide; markers stay in the file and you fix it by hand before continuing.
-
Finish the operation
git add dosya.txt
git cherry-pick --continue____
Show answer
git add dosya.txt
git cherry-pick --continuecontinue
-
Conflict steps
- conflict
- Same line changed twice
- resolve
- You fix the conflict by hand
- git add
- Marks the resolved file
- --continue
- Finishes the operation
Next lesson: Summary - Cherry-pick