Junior — Middle
Explain the principle of operation of the 'git rebase' command and how it differs from 'git merge'.
sobes.tech AI
Answer from AI
The git rebase command allows you to move one branch onto another, rewriting the commit history as if the changes were made on top of the new branch. This helps to obtain a linear history without additional merge commits.
Differences from git merge:
git mergecombines branches, creating a new merge commit, preserving the history of both branches.git rebaserewrites history by moving commits, making the history cleaner and more linear.
Example:
git checkout feature
# Rebase the feature branch onto the latest master
git rebase master
After this, the commits in feature will appear as if they were created on top of the latest commit in master.
Important: It is not recommended to rebase public branches, as this changes history and can cause conflicts for other developers.