Git Rebasing: Difference between revisions
No edit summary |
|||
Line 33: | Line 33: | ||
==Rebasing at the HEAD of the Base Branch== | ==Rebasing at the HEAD of the Base Branch== | ||
This procedure takes all commits from the head branch that diverged from the base branch, squashes them into one, and applies to the HEAD of the base branch. | |||
You will be given the chance to squash extraneous commits. Change "pick" into "s" for the commits you want squashed into the previous (above) commits. | |||
You will then be given the chance to edit comments. | |||
If you don't want to squash, you can omit -i. | |||
On branch topic/... | |||
Your branch and 'origin/topic/...' have diverged, | |||
and have 1 and 2 different commits each, respectively. | |||
(use "git pull" to merge the remote branch into yours) | |||
git push --force | |||
You can delete the branch (locally and remotely) |
Revision as of 17:27, 6 August 2019
Internal
Overview
Be aware that rebasing rewrites history.
When two branches are involved in rebasing, and in merging in general, we use the following terminology: the branch the changes to merge come from is named the "head" branch, and the brach to merge into is named the "base" branch.
Simple Rebasing
Only two branches are involved.
More Complex Rebasing
Rewriting History
Rebasing removes the commits that have been applied to the target branch from repository.
Practical Use Cases
Moving a Branch Forward
You are working on a feature branch, named "A", created when the "develop" branch HEAD was commit "ef5". You committed work on the "A" branch, and your commit is "3ba". After a while, you want to apply your changes on the HEAD of "develop", since "develop" has evolved and you want to try
On branch task/of/PLAT-15252 Your branch and 'origin/task/of/PLAT-15252' have diverged, and have 164 and 1 different commits each, respectively. (use "git pull" to merge the remote branch into yours)
Rebasing at the HEAD of the Base Branch
This procedure takes all commits from the head branch that diverged from the base branch, squashes them into one, and applies to the HEAD of the base branch.
You will be given the chance to squash extraneous commits. Change "pick" into "s" for the commits you want squashed into the previous (above) commits.
You will then be given the chance to edit comments.
If you don't want to squash, you can omit -i.
On branch topic/... Your branch and 'origin/topic/...' have diverged, and have 1 and 2 different commits each, respectively. (use "git pull" to merge the remote branch into yours)
git push --force
You can delete the branch (locally and remotely)