Menu
Coddy logo textTech

Слияние и перебазирование

Объединяйте работу из двух веток с помощью merge, rebase, squash и 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.

Часто задаваемые вопросы

Should I use git merge or git rebase?
Rebase your own unpushed feature branch to keep history linear; merge everything shared. The golden rule: never rebase commits that others may have based work on - rewriting published history forces everyone downstream to untangle it.
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?
Run 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.