0

Using Git, how do I see a diff of changes under a specified directory made since my last commit that impacted the directory? It would be nice to have a fully automated one-liner that I could assign to an alias.

Edward Brey
  • 40,302
  • 20
  • 199
  • 253
  • http://stackoverflow.com/questions/8382019/how-do-i-git-diff-on-a-certain-directory – 0xAX Jul 05 '14 at 11:46
  • 2
    @0xAX [How do I git diff on a certain directory](http://stackoverflow.com/q/8382019/145173) talks about scoping to a directory, but not in scoping the depth of the diff report to changes since my last commit that impacted that directory. – Edward Brey Jul 05 '14 at 11:50
  • Not a duplicate of [How do I git diff on a certain directory](http://stackoverflow.com/questions/8382019/how-do-i-git-diff-on-a-certain-directory), but ***probably a duplicate of some other questions*** laying around on Stack Overflow... –  Jul 05 '14 at 18:54
  • See also: [How to diff one file to an arbitrary version in Git?](http://stackoverflow.com/q/5586383/456814). You can actually apply the same answers to (sub)directories. –  Jul 05 '14 at 19:54

3 Answers3

2

If you don't mind hardcoding your email address and having to switch to the directory in question before running your command, something like this should work:

git config alias.mydiff \
    '!git diff $(git log --author you@domain.tld -n 1 --format="%h" .) HEAD .'

In case you would prefer to add this to your configuration file manually, here is what Git inserts into my configuration file when I execute that command:

[alias]
        mydiff = !git diff $(git log --author you@domain.tld -n 1 --format=\"%h\" .) HEAD .
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • @jthill, I don't think so. The `.` should restrict both `git log` and `git diff` to the current directory. I did say "If you don't mind ... having to switch to the directory in question before running your command". – ChrisGPT was on strike Jul 05 '14 at 20:31
  • This looks like what I want, but the command fails on Windows. Git just responds with the `git config` usage syntax. My attempts to add the alias directly to .gitconfig where also unsuccessful. – Edward Brey Jul 06 '14 at 10:52
  • @EdwardBrey, which shell are you using on Windows? Git bash? `cmd.exe`? This alias actually executes as a shell command, so the shell that you are using will be important. I have updated my answer to show what Git puts into my config file when I run this command. – ChrisGPT was on strike Jul 06 '14 at 12:44
0

You can use folder name in your diff-command:

git diff folder_name/
ceth
  • 44,198
  • 62
  • 180
  • 289
0

git diff allows you to specify arbitrary commits to diff with, so if you already know your last commit <last>, then you should be able to do

git diff <last> -- directory

Note that the above command is shorthand for

git diff <last> HEAD -- directory

where HEAD represents your currently checked out commit.