Merging & Rebasing
Kombiniere die Arbeit aus zwei Branches mit merge, rebase, squash und cherry-pick.
Combining branches: merge, rebase, and friends
Git gives you two ways to combine branches. git merge ties them together with a merge commit and preserves history exactly as it happened. git rebase replays your commits on top of the other branch, producing a straight line with no merge commit. Neither is "better" - merge is safer for shared branches, rebase keeps a feature branch clean before it lands.
Around those two sit the precision tools: git cherry-pick to carry a single commit across branches, interactive rebase to squash a messy series of commits into one, and git merge --abort for the moment a conflicted merge is more trouble than it is worth.
Häufig gestellte Fragen
Should I use git merge or git rebase?
How do I cancel a merge with conflicts?
git merge --abort stops the in-progress merge and returns the branch to exactly the state it was in before you started. If the merge already completed, undo it with git revert -m 1 <merge-commit> instead.How do I squash several commits into one?
git rebase -i HEAD~N for the last N commits, keep pick on the first line and change the rest to squash (or s). Git combines them into a single commit and lets you write its message. On GitHub, "Squash and merge" does the same at PR merge time.