355

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.

0

6 Answers 6

382

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
4
  • 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
    Commented Apr 7, 2018 at 21:37
  • 2
    What if the directory was deleted in the current head? Commented Apr 26, 2020 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. Commented Jan 11, 2022 at 1:57
  • 2
    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/ Commented Sep 9, 2022 at 2:43
85

Enter

git log .

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

3
  • 7
    Not worked for me..After landing in specific directory and giving the git log . gave me all commits from root.
    – AKS
    Commented Feb 3, 2018 at 4:15
  • 3
    Works for me. Using git bash
    – buckley
    Commented Feb 1, 2019 at 14:21
  • 1
    This works; however, one should be especially careful when using this in combination with -n <number> 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. Commented Aug 5, 2020 at 11:15
41

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

gitk -- foo/A

Enter image description here

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.

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.

1
  • 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. Commented Nov 5, 2021 at 19:01
7

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
1
  • The other answers only show what OP asked for. You just added a random additional unneeded specification. Commented Dec 3, 2023 at 13:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.