How to show Git log history (i.e., all the related commits) for a sub directory of a Git repository
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.
Solution 1:
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:
Enter
git log .
from the specific directory. It also gives commits in that directory.
Solution 3:
If you want to see it graphically you can use gitk:
gitk -- foo/A
Solution 4:
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.