Suppose we have the below git log -
$ git log --oneline
1828a2c (HEAD -> atul, origin/master, origin/HEAD, master) fixed the line 4
aa9006c updated 3rd line
b234a71 com3
6f30710 bad
b52159d com2
3433afb com1
050082d Initial commit
If we want to revert the change 6f30710 bad, we need to simply run the git revert like below -
$ git revert 6f30710
This will open editor to change the commit message if you want to, by default it shows Revert "bad" which is good enough for me so save the file in editor, as soon as you save the comment file, it will create the another commit with reverse changes.
Your git log will be look like this -
$ git log --oneline
9055ed1 (HEAD -> atul, origin/master, origin/HEAD, master) Revert "bad"
1828a2c fixed the line 4
aa9006c updated 3rd line
b234a71 com3
6f30710 bad
b52159d com2
3433afb com1
050082d Initial commit
9055ed1 (HEAD -> atul, origin/master, origin/HEAD, master) Revert "bad"
1828a2c fixed the line 4
aa9006c updated 3rd line
b234a71 com3
6f30710 bad
b52159d com2
3433afb com1
050082d Initial commit
Git revert is the simplest and safest way to revert the public changes (which has been pushed to remote repository). As we can see, git revert doesn't alter the change history, so if you want to revert the change 9055ed1, you can do it by running another revert command. All the revert operations will be maintained by git in log which tell you what you have did with each commit and it is visible to all the git repo contributor. Hence, git revert is the best tool for reverting the public changes.
Like the below page to get the update
Facebook Page Facebook Group Twitter Feed Telegram Group
No comments:
Post a Comment