Advanced Git
Amanda Crawford-Adamo
Software and Data Engineer
Git Rebase Command:
git rebase <branch_name>
data-cleanup
feature branch.git checkout data-cleanup
main
branch onto data-cleanup
branch.git rebase main
data-cleanup
commits are recreated after main
's latest commitdata-cleanup
commits get new hashesNote: If there are any conflicts, these would need to be resolved manually.
git rebase -i <commit_hash>
Functionality
Warning!
main
$$
Here is the data-validation branch history before we edit the commit history.
$ git log --oneline data-validation
abc1234 Optimize validation performance
def5678 Fix validation bug
ghi9101 Add data validation function
xyz1234 New Main Branch Commit
vwx7890 Main Branch Commit
jkl2345 Initial commit
Here's how we edit the commit history using pick and fixup commands in the open editor.
$ git rebase -i HEAD~3
pick ghi9101 Add data validation function
fixup def5678 Fix validation bug
fixup abc1234 Optimize validation performance
# Rebase xyz1234..abc1234 onto HEAD~3(xyz1234) (3 commands)
#
# Commands:
# p, pick <commit> = use commit
# f, fixup <commit> = like "squash", but discard this commit's log message
...
Before
$ git log --oneline data-validation
abc1234 Optimize validation performance
def5678 Fix validation bug
ghi9101 Add data validation function
xyz1234 New Main Branch Commit
vwx7890 Main Branch Commit
jkl2345 Initial commit
After
$ git log --oneline data-validatoin
mno6789 Add data validation function
xyz1234 New Main Branch Commit
vwx7890 Main Branch Commit
jkl2345 Initial commit
The following commits are combined into one
Merge
Rebase
Merge
For integrating completed features, preserving development context
Rebase
For keeping feature branches updated with main, or for cleaning up before merging
Remember
Advanced Git