[WP] 01.05.2023 | git-rebase
fig 1.1 git rebase scheme<atlassian.com> |
This post is about git rebase command. Rebase along with merge is a way to join main branch and feature branch. Merge is about forward moving change record. On the other hand rebase comes with amazing history re-writing features. In simple words rebase operation is about moving or combining a sequence of commits to a new base commit. To rebase current branch simply type rebase and put a commit_id as an argument. #git rebase <base commit id>. Changing a base of your branch looks as if you started this branch from totally different commit than origin. Under the hood git creates whole new commits and apply them to base commit specified within command. Let’s make it clear the branch starts from a different commit looks the same but contains brand new commits. It may look senseless but rebase have crutial meaning if it comes to maintain a linear commits history within your repo.
One good example of git rebase application is the following situation:
- You are working on a separate feature branch
- Since youve been working there were several updates to main branch.
- You need to keep your commit history clean.
It is a good oportunity to use git rebase. Very often rebase command is used to polish a feature branch before merge it into the main codebase. (e.g. squash insignificant commits, delete obsolete commits).
3 way merge together with merge commit is a result of git merge operation. Git rebase lets fast forward merge and maintain clean history.Clean history of official records looks good and is clear to understand and maintain. What is more one of the main benefits of clean history is that it helps investigate introduction of a regression using git bisect. Integration of your feature may be done in two ways 1.direct merge or 2. rebase and then merge.
Last but not least it it is important not to execute history rewriting in connection with –force pushing. This kind of action has capability to overwirte other remote user work once they execute pull command.
cheers
g-marcin
cheers
g-marcin
Komentarze
Prześlij komentarz