bdimych
bdimych

Reputation: 311

Non-recursive git log and diff

git log -p .

only within the current directory but not in subdirectories

equivalent

svn log --diff --depth files .

Is it possible?

Upvotes: 9

Views: 2396

Answers (3)

Philip Beber
Philip Beber

Reputation: 1233

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.

Upvotes: 0

Mike Kinghan
Mike Kinghan

Reputation: 61575

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.

Upvotes: 1

JB.
JB.

Reputation: 42154

How about:

$ git log -p file1 file2 ...

Or, if they're too many to type:

$ find . -maxdepth 1 -type f | xargs git log -p

Upvotes: 3

Related Questions