Search code examples
gitfilecommithistorygit-extensions

Git: How to filter to only check for changes on a single file, from recent commits


I would like to know, how to see only the changes that an individual file within a large repo, has gone through. And how to possibly revert the last x commits on it

I use Git Extensions mainly, but can also work with git bash.


Solution

  • To get a list of the commits for path/to/file.txt:

    git log -- path/to/file.txt

    When you've found the commit you want to revert the file to by using git log you need to get the first 7 characters in the SHA. It will look something like: b81eb8e. Test that you have the correct SHA by running (replace example SHA with your SHA):

    git show b81eb8e

    When you have confirmed the SHA run:

    git checkout b81eb8e path/to/file.txt

    Then the file is reverted on your file system, and the last thing you need to do is to commit this new edit.