git revert vs git rebases

Norman Fung
3 min readMar 27, 2021

Difference between git revert vs git rebases? Git revert allow us to revert to a particular commit. Git rebase allow us to cherry pick which one to drop!

Add seven files first

Test 1: Git reset

git reset — hard e9ec32ab33cca4c38fb4f304cd764a861bc66f98

git push — force

Note file6 and file7 both disappeared.

And from GitExtension you can see the same in Commit history

Same from git log — pretty=oneline

Test 2: Git rebase

We only have file1, file2, file3, file4 and file5 now. What if we want to keep only file1,file3 and file5? Delete file2 and file4

git rebase -i HEAD~5

This will pop open:

Now cherry pick your commits:

When done, you still need to push your changes

Also locally you can see file2 and file4 gone

Now push your changes

Git push — force

Note commit hash of file1 file3 file5 different

Test 3. Git rebase and conflict resolution

Create a test file: test.py

Then add a line in it , repeat five times (i.e. five commits)

git rebase -i HEAD~5

Say drop msg3

You’d get merge conflict because msg1, msg2, msg3, msg4, msg5 are all in same file “test.py”

To resolve conflict, open test.py

Delete bottom bits

git add test.py

git commit -m “Resolve rebase conflict”

git -c rebase.autoSquash=true rebase — continue

git push — force

You’re done!

--

--

Norman Fung

#python #web3 #crypto #trading #nft #blockchain #smartcontract #journey2makemoneyscientifically