How to show Git log history (i.e., all the related commits) for a sub directory of a Git repository

Git

Git Problem Overview


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.

Git Solutions


Solution 1 - Git

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

Solution 2 - Git

Enter

git log .

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

Solution 3 - Git

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

gitk -- foo/A

Enter image description here

Solution 4 - Git

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.

Solution 5 - Git

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

Solution 6 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionamsView Question on Stackoverflow
Solution 1 - GitGoZonerView Answer on Stackoverflow
Solution 2 - GitNikhil AgarwalView Answer on Stackoverflow
Solution 3 - GitRezaView Answer on Stackoverflow
Solution 4 - GitNick TomlinView Answer on Stackoverflow
Solution 5 - GitMatthias MView Answer on Stackoverflow
Solution 6 - GitMafu JoshView Answer on Stackoverflow