Git Rebase vs Merge: nuq lo'
git merge 'ej git rebase feature branch changes main Daq nob. yIch rap: Hoch pIm Sovbe', history tangled pagh rewritten (neH pagh). cha' mIw Qagh rap 'ach pIm: Qagh mIw lo' vaj force-push disaster pagh unreadable commit graph.
wa'-wa' nuq Qu'
main choH (branch qaSpa'), feature branch commits ghaj:
A---B---C feature
/
D---E---F---G main
Merge chu' commit chenmoH, cha' histories bind, cha' parents:
git checkout feature
git merge main
A---B---C-------H feature
/ /
D---E---F---G-------- main
A, B, C choHbe'. H merge commit chu': "cha' history lines DaH bind". full history (F G qaSpa' branch) Dach.
Rebase commits tlhap 'ej wa'-wa' new base Daq replay:
git checkout feature
git rebase main
D---E---F---G---A'---B'---C' feature
A', B', C' chu' commits - changes rap, messages rap, parent pIm, hashes pIm. branch point Qaw'; G vo' branch 'ej wej commits straight line ghItlh legh.
distinction qatlh
core trade-off: merge real qaS preserve; rebase cleaner history chenmoH (literal qaS pagh). cha' Dun - audiences pIm.
- Merge parallel work honest. cha' people old
mainDaq build, branches diverge reconverge vaj merge commit truth record. non-destructive: commit choH pagh. shared branches Daq safe. - Rebase history serial legh.
git logclean line (merge lattice pagh). 'ach commit hashes rewrite - danger.
qatlh rule: shared history rebase Qo'
git checkout feature
git rebase main
git push --force-with-lease
feature SoH neH Qu' vaj Dun. feature (pagh main) others pull 'ej build vaj rebase history rewrite: local branch remote diverge, next pull tangle pagh local commits vanish (vanish pagh - branch reachable pagh).
rule: branches SoH neH push rebase freely; shared merge (pagh rebase-and-fast-forward PR tool).
interactive rebase: share qaSpa' cleanup
rebase Dung use: base pIm pagh - unpushed commits cleanup PR qaSpa'.
git rebase -i HEAD~4
editor poSmoH, loS commits list: reorder, squash "fix typo" "actually fix typo", messages reword - others legh qaSpa'. safest common use: messy work-in-progress history coherent commits choH.
merge conflicts pIm
merge conflicts wa'logh resolve. rebase commits law' same lines touch vaj conflict repeat (commit Hoch) - tedious 'ach precise: historical change context Daq resolve.
git rebase main
# CONFLICT in commit B
# ...resolve...
git add .
git rebase --continue
# CONFLICT in commit C, same lines
# ...resolve again...
git add .
git rebase --continue
rebase repeated-conflict slog vaj git rebase --abort start Daq nob. qaw!
practical default
- own feature branch,
maincatch up:rebase. - PR qaSpa' commits cleanup:
rebase -i. - finished reviewed feature
mainDaq: team convention - cha' Dun, consistency qatlh. - pushed (pagh pulled):
merge, pagh rebase team agreement rap.
yaj
Merge parallel history truth (tangled graph). Rebase clean linear graph (commit identity rewrite). "nuq Dun" pagh - commits rewrite SoH neH ghaH'a'.