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

git

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.

Best Answer

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