2

I need to get a list of remotely changed files as a single line that I then process line by line to generate a list of outdated files.

But I am astounded that out of all the possible pretty format %tokens, there is not one to get the filename: https://git-scm.com/docs/pretty-formats

git log --pretty=format:'%f' -- 'myfilename-to-check';

pretty=format:'%f' will give me the commit message, but how can I get the filename inside the pretty format.

Yes I know I can do --name-only or --name-status but that does not allow me to format the output exactly as I need it.

Is there no formatting %token / %key that shows the filename ?

Update

My apologies, I forgot to state that that there are multiple filenames to check:

git log --pretty=format:'%f' -- 'myfilename-to-check-1' 'myfilename-to-check-2' 'myfilename-to-check-3' 'myfilename-to-check-...etc...';
crankshaft
  • 2,607
  • 4
  • 45
  • 77

2 Answers2

1

There is not such placeholder for changed files. Here is a workaround in bash.

git rev-list HEAD -- myfile-to-check | while read commit;do
    echo $(git log -1 $commit --pretty=format:'%h-%f' --name-only)
done

git rev-list prints the commit hashes that change myfile-to-check. echo and git log -1 prints the short hash, sanitized subject, and changed files of each commit one by one.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53
0

Since this does not seem to be supported, you can simply concatenate the filename to each line of your git log output, using sed for instance

git log --pretty=format:'%f' -- 'myfilename-to-check'| sed 's/$/ myfilename-to-check/'
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250