I would like a way to log certain commits and also submit path arguments so that the diff on those paths, if any, is shown for each commit as if those path arguments were supplied like git diff -- <path args>
.
git log -p <path args>
almost accomplishes this. Here's how I'd like it to work:
$ git log develop..mybranch -p mydir
1010101 my commit msg
(diff of files in mydir)
2323232 my other commit msg
(nothing here because the commit doesn't touch mydir)
The problem is that the second commit wouldn't be shown, because it does not touch mydir
.
How can I achieve the equivalent of git log -p <path args>
, but not skipping commits that don't touch the given paths?
git log <path args>
automatically limits commits to those touching <path args>
and there is no way to list other commits. Hence there is no simple way to do what you want. Can be done by listing all commits, parsing the list, looking into every commit and processing commits one by one. Like this:
git rev-list develop..mybranch |
while read sha1; do
git show -s $sha1 # show the commit
git diff $sha1~ $sha1 -- mydir # will be empty if the commit doesn't touch mydir
done
Two commands (git show
, git diff
) for every commit. On a big repository it could be slow so the code would require optimization.