How to show a commit’s patch pertaining to a specific path?

Written on by Matija Marohnić in Improving Workflow

When viewing the patch of a certain commit with git show <commit> you’re only interested in a certain part of it, related to a file or a directory. In that case instead of searching for that part of the patch you can simply append the path:

git show <commit> -- <path>

So, for example, if you wanted to see which changes were made to the files inside the directory helpers/users by the commit 72c8fbde, you would run:

git show 72c8fbde -- helpers/users

Sign up below to receive updates, tips and more handy tutorials when git screws up. It’s good stuff & I don’t spam.