Git Thoughts - Part II - What is rebase?

 

Change branch “location” by applying the changes from the commits in another point of the repository tree.


How does the process work?


  • The new location for the branch is chosen.

  • The process is done, commit by commit, with the same order they were created.

  • Each commit is applied, starting in the new location and after on the previous commit applied.

  • One commit at a time. If it detects any conflict that cannot be resolved automatically, the process is paused and will need user intervention so it can continue.

  • Until all the commits are successfully applied, all changes are made in a detached Head and the process can be canceled and reverted easily.

  • After applying all the commits and all the eventual conflicts resolved, the head of the branch rebased, now points to the new “last commit”.

  • Every commit has new references so there is now connection between the commits from the original branch and the new one. 


There are several variations that can be made controlled by the user, that is called:

 

--interactive rebase.


One of them is the use of squash. Squash is the action of joining the changes of two or more consecutive commits in one. Looking to the process of rebase i can say:

  • The new location is the point right before the first commit to be squashed with another

  • Instead of all commits in a branch, we choose the ones we want

  • Instead of committing at each interaction, it only commits at the end.


Well, this is a dummy guide from a dummy to dummies. So for now it is good.

Git Documentation link:https://git-scm.com/docs/git-rebase

Comentários