Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Rebase a branch on main
While you worked, main moved on. Rebase replays your commits on the new main.
before: main A---B---C
\
feature D---E
after: main A---B---C
\
feature D'--E'Onthoud
Rebase rewrites commits (new hashes D', E'). Never rebase commits other people already built on — only your own feature branch.
Solve conflicts during a rebase
A rebase stops at each commit that conflicts. Fix it, then continue.
Clean up commits interactively
git rebase -i opens a list of your commits. Change the word in front to squash, reword, reorder or drop commits — before you open the pull request.
git rebase -i origin/mainpick 1a2b3c4 Add web subnet
fixup 5d6e7f8 typo
pick 9a8b7c6 Add NSG rules
reword 3c4d5e6 wip
drop 7f8e9d0 debug output| Word | Effect |
|---|---|
pick | Keep the commit |
reword | Keep, change the message |
squash | Join with the commit above, edit the message |
fixup | Join with the commit above, keep its message |
drop | Remove the commit |
Op het werk
Commit with git commit --fixup=HASH while you work, then git rebase -i --autosquash origin/main puts every fix in the right place.
Choose merge or rebase
Both bring changes together. Teams pick a style and stick to it.
| Merge | Rebase | |
|---|---|---|
| History | True, with merge commits | Straight line |
| Safe on shared branches | Yes | No (rewrites) |
| Conflicts | Once | Possibly per commit |
| Common use | Merging a PR into main | Updating your own feature branch |
Pick single commits
git cherry-pick copies one commit from another branch — for example a hot fix from main into a release branch.