Git: resolving a conflict
When Git cannot merge on its own: the same lines changed on both sides, conflict markers, resolving, staging, concluding the merge or abandoning it with merge --abort.
- 20 cards
- 5 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- Scenarios
- Understand
A few cards from the deck
Merge conflict: what is it?
Show the answer
A situation where two branches changed the same lines of a file, or one deleted what the other changed: Git cannot choose on its own.
Git compares each side with the common ancestor. If the changes do not overlap, it merges on its own; otherwise it stops and asks you to decide.
You are on branch main and run
git merge menu. What does the block between<<<<<<< HEADand=======represent?
```text
<<<<<<< HEAD
Salut
=======
Hello
>>>>>>> menu`- The version from branch main, the one you are on
- The version from branch menu, which you are merging
- The version from the common ancestor of the two branches
- The version on the remote repository, before your last commit
Show the answer
The version from branch main, the one you are on
The top is what HEAD, hence your current branch, contains; the bottom is what the merged branch brings. The common ancestor is not shown by default.
In a conflicted file, the block between the opening marker and the separator is the version from the … branch, and the one between the separator and the closing marker is from the … branch.
Show the answer
In a conflicted file, the block between the opening marker and the separator is the version from the current branch, and the one between the separator and the closing marker is from the merged branch.
The opening marker carries HEAD, which is the branch you are on; the closing marker carries the name of the branch you are merging.
Conflict markers: what is it?
Show the answer
Lines Git writes into the file to delimit the two versions: an opening, a separator and a closing.
They open with seven less-than signs and HEAD, split with seven equal signs, close with seven greater-than signs and the other branch's name. They must never be committed.
A conflict on t.txt is beyond you and you want to go back to the state before the merge. What do you do?
git switch mainto leave the mergegit commit -am "conflict"to resume latergit branch -d menuto delete the faulty branchgit merge --abort
Show the answer
git merge --abortgit merge --abortcancels the merge without losing anything.git switchis refused during a merge (“cannot switch branch while merging”), committing would record the markers, and deleting the branch settles nothing.