Search code examples
gitgit-revert

Git revert explanation


Reading online, I understand the git revert cancels a single commit from the past, but I am unclear as to what that means unless the cancelled commit is the last commit performed.

For example, observe the following three versions of a file:

"a" => "aa" => "a|a"

If I reverted the 2nd version, what would the 4th version look like? "|a" or "a|"?


Solution

  • Revert work by creating a patch which is the opposite of the changes introduced in the commit you want to revert and try to apply it, then create a commit.

    If the patch do not apply due to some changes introduced by commits in between, you will have to resolve conflicts...

    I hope it will help you better understand how it works.

    PS: your notation won't help to understand and explain how revert works because changes are at line level and not file one...