Git Rebase
Last updated
Last updated
When i first leaned git , i was told to avoid rebasing ta all costs .
Rebasing . It actually very useful , as long as your know when not to use it
There are two main ways to use the git rebase command :
as an alternative to merge
as a cleanup up to
We can instead rebase the features branch onto the master branch . This moves the entire feature branch so that is begins at the tip of the feature branch. ALl of the work is still there , but we have re-writen history
instead of using a merge commit . rebasing rewriten history by creating new commits for each of the original features commits
We ge a much clearner project history . No unnecessary merge commit! We end up with a linear project history.
Never rebase commits that have been shared with others. if you have already pushed commits commits up to github.. do not rebase them unless you are positive no one on the team is using those commits
Running git rebase with the -i option will enter the interactive mode, which allows us to edit commit, add files,drops commits,etc . Note that we need to s[ecify how far back we want rewriten history .
Also notice that we not rebasing onto antther branhc. Instead,WE are rebasing a sreies of commits onto the HEAD rhey currenly are based on .
In our text editor, we'll see a list of commit alongside a list of commaands that we can choose from. Here are a couple of the more commony use commands:
pick - use the commit
reword - use the commit, but edit the commit message
edit - use commit, but stop for amending
fixup - use commit contents but meld it into previous commit and discard the commit message
drop - remove commit