Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
git merge feature/login-limit
CONFLICT (content): Merge conflict in app/config.py
Automatic merge failed; fix conflicts and then commit the result.
git status
git add app/config.py
git commit
git merge --abortFix the file, git add it, git commit (or git merge --continue). git merge --abort goes back to before the merge.
Step by step
- List the files with conflicts:
- Read the markers in each file:
<<<<<<< HEAD
LOGIN_RATE_LIMIT = "10/minute"
=======
LOGIN_RATE_LIMIT = "5/minute"
LOGIN_LOCKOUT_MINUTES = 15
>>>>>>> feature/login-limitThe part between <<<<<<< HEAD and ======= is your current branch; between ======= and >>>>>>> is the branch you merge in.
- Decide and edit — keep one side, or combine both. Remove all three marker lines:
LOGIN_RATE_LIMIT = "5/minute"
LOGIN_LOCKOUT_MINUTES = 15- Take one whole side for a file (for example a generated lock file):
git checkout --theirs package-lock.json
git checkout --ours docs/CHANGELOG.md
git add package-lock.json docs/CHANGELOG.mdFor lock files, often the best way is: take one side, then run the tool again (npm install) and commit the new lock file.
- Finish:
Run the tests before you push — the merged code is new code.
- During a rebase the words switch places:
--oursis the branch you rebase onto (main),--theirsis your commit. Continue commit by commit:
- Make conflicts rare: small pull requests, merge
maininto your branch (or rebase) often, agree on formatters (Black, Prettier) so style changes do not collide, and let Git remember your resolutions:
zdiff3 also shows the original lines between the two sides — much easier to decide.
Check that it worked
Common problems
| Problem | Cause | Fix |
|---|---|---|
| Markers were committed by mistake | The file was added before it was fixed. | Fix it in a new commit; add a CI check (or pre-commit) that fails on markers. |
You have not concluded your merge (MERGE_HEAD exists) | A merge is still open. | Finish (git commit) or git merge --abort. |
--ours took the wrong side | During a rebase ours/theirs are switched. | Check again: in a rebase, --theirs = your commit. |
| The same conflict on every rebase | Long-living branch, conflict repeats per commit. | rerere; or squash your commits first; or merge instead of rebase. |
| Binary file conflict (image, PDF) | Git can not mix binary files. | Choose one: git checkout --ours/--theirs FILE. |
| Code merged without conflict but is broken | Both changes are fine alone but not together. | Tests in CI on the merged result; required status checks. |
Go further
- Command pages: git.
- Next how-tos: Undo the last Git commit, Create a CI pipeline in GitHub Actions, Sign Git commits, Rebase a branch on main.
- Learn it: Git — Merge conflicts, Git — Conflicts during a rebase, Git — Rebase or merge?, Git — Pull requests.
- Practise: Lab: branches, a real merge conflict and a protected main.
1In a merge conflict, which part is between <<<<<<< HEAD and =======?
The version of your current branch.
2During git rebase main, what does git checkout --theirs FILE take?
Your own commit's version — in a rebase, ours and theirs are switched.