I'm using this git command to create an archive of the files modified within a specific commit:
git archive -o update.zip HEAD $(git diff --name-only COMMITID^)
where COMMITID is the id of the commit I'm looking to archive. This works fine from the command line but I would like to run it from a batch file. Here are the contents of the batch file I'm using:
git archive -o update.zip HEAD $(git diff --name-only %1^^)
where %1 is the commit id being passed in via SourceTree. The problem I'm having is that this command when run from a batch file returns the following error:
error: unknown option `name-only'
I'm guessing there may be some character escaping issues going but I'm unable to find what is specifically breaking.
How would I write that git command so that it will work from a batch file?
UPDATE
I tried removing the --name-only option and received the following error when trying the batch script via SourceTree:
fatal: path not found: $(git
Hopefully that helps narrow down what may be going on.
FURTHER UPDATE
Turns out my syntax was wrong for grabbing only the modified files from a specific commit but using msandiford's answer I came up with this batch file script that works perfectly:
setlocal enabledelayedexpansion
set output=
for /f "delims=" %%a in ('git diff-tree --no-commit-id --name-only -r %1^^') do ( set output=!output! "%%a" )
git archive -o update.zip HEAD %output%
endlocal
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…