339

Let’s say that I have a Git repository that looks like this:

foo/
  .git/
  A/
   ... big tree here
  B/
   ... big tree here

Is there a way to ask git log to show only the log messages for a specific directory? For example, I want to see what commits touched files in foo/A only.

Paolo
  • 20,112
  • 21
  • 72
  • 113
ams
  • 60,316
  • 68
  • 200
  • 288

6 Answers6

367

From directory foo/, use

  git log -- A

You need the '--' to separate <path>.. from the <since>..<until> refspecs.

# Show changes for src/nvfs
$ git log --oneline -- src/nvfs
d6f6b3b Changes for Mac OS X
803fcc3 Initial Commit

# Show all changes (one additional commit besides in src/nvfs).
$ git log --oneline
d6f6b3b Changes for Mac OS X
96cbb79 gitignore
803fcc3 Initial Commit
GoZoner
  • 67,920
  • 20
  • 95
  • 145
  • 1
    @GoZoner, is there a way to find all commits where a specific folder name was changed? the folder could have moved around, so I would prefer not have to hunt down how and where the folder moved.. – alpha_989 Apr 07 '18 at 21:37
  • 2
    What if the directory was deleted in the current head? – Aaron Franke Apr 26 '20 at 22:19
  • keep in mind that this command will return expected results relatively to requested "path". In case of path=A you are ok if you are running from "foo/". However if you are inside "A" it will probably yield no results. – Yury Kozlov Jan 11 '22 at 01:57
  • As a quick read `git log -- A` could perhaps show the minimal command that is immediately understandable without reading any explanation text, such as `git log -- folder/` – Jason Doucette Sep 09 '22 at 02:43
73

Enter

git log .

from the specific directory. It also gives commits in that directory.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nikhil Agarwal
  • 747
  • 5
  • 2
  • 6
    Not worked for me..After landing in specific directory and giving the git log . gave me all commits from root. – AKS Feb 03 '18 at 04:15
  • 2
    Works for me. Using git bash – buckley Feb 01 '19 at 14:21
  • This works; however, one should be especially careful when using this in combination with -n to limit the number of log messages. If you accidentally type "git -n 3." instead of "git -n 3 ." (note the missing space between 3 and .), git happily displays the history of the whole repo. – Frank Schmitt Aug 05 '20 at 11:15
41

If you want to see it graphically you can use gitk:

gitk -- foo/A

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Reza
  • 18,865
  • 13
  • 88
  • 163
29

You can use git log with the pathnames of the respective folders:

git log A B

The log will only show commits made in A and B. I usually throw in --stat to make things a little prettier, which helps for quick commit reviews.

Nick Tomlin
  • 28,402
  • 11
  • 61
  • 90
7

For tracking changes to a folder where the folder was moved, I started using:

git rev-list --all --pretty=oneline -- "*/foo/subfoo/*"

This isn't perfect as it will grab other folders with the same name, but if it is unique, then it seems to work.

Mafu Josh
  • 2,523
  • 1
  • 23
  • 25
  • 1
    This is the only solution that will work if the specified path does not exist in your current work-tree. E.g. if it's only present on a bunch of topic branches. – Dmitry Avtonomov Nov 05 '21 at 19:01
6

The other answers only show the changed files.

git log -p DIR is very useful, if you need the full diff of all changed files in a specific subdirectory.

Example: Show all detailed changes in a specific version range

git log -p 8a5fb..HEAD -- A B

commit 62ad8c5d
Author: Scott Tiger
Date:   Mon Nov 27 14:25:29 2017 +0100

    My comment

...
@@ -216,6 +216,10 @@ public class MyClass {

+  Added
-  Deleted
Matthias M
  • 12,906
  • 17
  • 87
  • 116