Search code examples
gitgit-revert

How to undo changes in a file after multiple commits in Git?


I'm working on a branch where I have changed file A in several commits and now I want to revert all changes from it so that file A's state is same as initial state it had when I had first created the branch. What is the easiest way to achieve this?


Solution

  • git checkout <sha1_of_commit> file/to/restore
    

    It will revert file to state after <sha1_of_commit> commit.

    If you want to revert it to state before this commit use

    git checkout <sha1_of_commit>~1 file/to/restore