Last Updated: February 25, 2016
·
2.21K
· epocsquadron

Git Alias to Show Affected Files in Last N Commits

This command is extremely useful if you are not using automated deployments and need to know what files to manually transfer since the last however-many commits.

Add this to your user's ~/.gitconfig under [alias] to make it globally available:

lsch = "!f() { git diff --name-status -r "HEAD~$1"; }; f"

You can invoke this to retrieve all affected files in the last 7 commits like so:

$ git lsch 7

Substitute the 7 with whatever number of commits back you want, or pass no option for only the most recent commit.

1 Response
Add your response

Instead of adding it manually to the .gitconfig file, just use the git alias command :
git config --global alias.lsch '"!f() { git diff --name-status -r "HEAD~$1"; }; f"'

To undo it, use git config --global --unset alias.lsch

I also use another alias which allows me to list the changed files between any two commits: git config --global alias.chgd 'diff --name-only'. You use it like so: git chgd master mybranch

over 1 year ago ·