task is to open Windows cmd in gitlab repository locally and get all commits from past month and for each commit find the diff and save it to .txt file named: date_commitId_diff.txt
So finally I want to have each commit's diff in txt file.
I'm able to get all commits with id:
git log --author=Piotr --date=short --before={2022-04-30} --after={2022-04-01} --pretty=format:"%h"
I also know how to print diff for particular commit_id:
git show 2a62555ff
but when I try to do FOR loop over commits:
for /f "delims=" %i in ("'git log --author=Piotr --date=short --before={2022-04-30} --after={2022-04-01} --pretty=format:"%h'") do git show %i
I get 'More?' question... and don't see solution to progress on it.
CodePudding user response:
Your first example uses pretty=format:"%h"
But your second uses --pretty=format:"%h'
: there seems to be a mismatched "
missing.
I would also avoid the double quotes around the 'git command'
for /f "delims=" %i in ('git log --author=Piotr --date=short --before={2022-04-30} --after={2022-04-01} --pretty^=format:"%h"') do git show %i
Note the ^
in --pretty^=format:"%h"
.
Without it, as explained here, you would get the error message "fatal: invalid object name 'format'.
".
To save them (each diff) in their own files:
for /f "tokens=1,2 delims= " %i in ('git log --author=Piotr --date=short --before={2022-04-30} --after={2022-04-01} --pretty^=format:^"%h