1

I often find myself wanting to open all the files that were changed in a certain commit. My current solution is this, in an alias:

$EDITOR $(git diff --name-only --relative <commit names>) 

Which works pretty well, but when I am in a subdirectory, then it doesn't open any files that were changed outside of that directory, because git diff --name-only --relative only outputs files changed in the current directory, not the whole repo. Is there a flag I can pass to git diff to make it include all changed files in the repo, even with --relative?

1
  • As a bonus, a way to not list the binary files would be handy. Commented Apr 1, 2015 at 0:38

1 Answer 1

1

Git's own aliases allow you to specify shell commands by defining the alias with a leading exclamation point. These shell-command aliases always execute from the repository root, so you can use them in conjunction with the command you're already using by defining an alias in your .gitconfig:

[alias] review-diff = "!edit() { $EDITOR $(git diff --name-only --relative \"$@\"); }; edit" 

Then you can run git review-diff from anywhere in the repository.

(Note: I'm not sure when the version difference is, but newer versions of Git seem to allow you to skip the function wrapper in the alias, making for a simpler setup:)

[alias] review-diff = "!$EDITOR $(git diff --name-only --relative \"$@\")" 
Sign up to request clarification or add additional context in comments.

2 Comments

This seems to be pretty close, I have "diff-file-list = !s $(git diff --name-only --relative \"$@\")" as an alias (s is a bash function that launches my editor) and if I do git diff-file-list HEAD^ HEAD it opens the files just fine, but it also opens a new file named HEAD and one named HEAD^. This somewhat does the trick, as I only ever really want to open the files from the most recent commit, the staged changes, or the unstaged changed, and I can do an alias for each, but a more general solution would be nice.
Have you tried the longer version with the function (the first one in the answer)? That one should avoid the problem with the parameters being appended on the end.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.