8
git log -p .

only within the current directory but not in subdirectories

equivalent

svn log --diff --depth files .

Is it possible?

bdimych
  • 291
  • 2
  • 8

3 Answers3

3

How about:

$ git log -p file1 file2 ...

Or, if they're too many to type:

$ find . -maxdepth 1 -type f | xargs git log -p
JB.
  • 40,344
  • 12
  • 79
  • 106
  • 2
    thanks for answer, but list of existing files is not enough, the problem is I want to look deleted files also – bdimych Sep 13 '15 at 19:10
  • I'm afraid there's no support for that sort of operation in git. If you really want something like that, you're going to have to hack together a helper to list current and former elements of your directory. – JB. Sep 13 '15 at 19:25
0

On Linux or the like you can list only the files in the current directory with:

ls -p | grep -v /

so:

git log -p `ls -p | grep -v /`

is one way to do it.

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
  • the file list can not be generated from the current working area. a normal git log behavior would evaluate the path against the version even when the path doesn't exist in the working area – yucer Oct 02 '16 at 10:47
0

Something like this will work:

git log --all --pretty=format: --name-only --relative="$(git rev-parse --show-prefix)" -- . | sed '/\//d ; /^[[:space:]]*$/d' | sort | uniq | xargs git log -p --
  • The first git command lists every single file ever, including deleted ones. Each file will be listed once for each time it was changed. The --relative will remove files not from this directory and also remove the subdirectory prefix from the file names.
  • Sed removes the ones not in the current directory (i.e. that don't contain a slash). This works because we removed the subdir prefix in the previous step. It also removes the empty lines.
  • Sort and uniq remove the duplicates.
  • Now we have the list of files we're interested in, xargs will pass them to git log -p. The -- is needed otherwise it won't know what to do with the deleted files.

It seems like an inefficient way of completing the task but I don't think git has the concept of "every file", it just has the current set of files and a list of diffs. So you have to go through every change set to get the complete list.

Philip Beber
  • 1,115
  • 12
  • 18