Hi I am a newbie to git and I don't understand what is the basic difference between git reset
and git revert
. Does git revert
reverts the merge being pushed ?
Notice that revert and reset are history altering (making a new commit in former, and moving the tip in the latter), where as restore does not modify history. Let's consider an example of when you'd want to use restore instead of revert or reset .
Summary. To review, git reset is a powerful command that is used to undo local changes to the state of a Git repo. Git reset operates on "The Three Trees of Git". These trees are the Commit History ( HEAD ), the Staging Index, and the Working Directory.
Removing the last commitTo remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.
As far as I know, they are doing totally different thing.
git revert
aimed to revert effects of previous commit. For example,
A <- B <- C
^ HEAD
If I found B I committed before is wrong, and I want to "undo" its change, git-revert
-ing B will cause:
A <- B <- C <- B'
^ HEAD
for which B'
is reversing the change done in B.
git reset
is more straight-forward, it is simply setting the HEAD to a certain commit,
A <- B <- C
^ HEAD
git-reset
-ting to B will give you
A <- B <- C
^ HEAD
git revert: Undoes a change part of a commit to the local/origin repo by creating a new commit.
command: git revert <id>
git reset: Git reset will delete/undo changes which are committed in local repo. It undoes changes by 3 ways, –soft, –mixed, –hard. Where mixed is the default value.
Working Dir (coding ) -> Staging Area(Index) -> local Repo (git push)
git reset –soft/mixed/hard –HEAD~N -> mixed is default
git reset --soft HEAD~N # will move file/changes from local commit to staging area
git reset --mixed HEAD~N #will move file/changes from local commit to working directory
git reset --hard HEAD~N #will delete file /changes from working directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With