Create archive of modified files in GIT via batch file
batch-file, git, windows
Solution
Assuming you need a windows batch file, and not a bash script, here is a minimal batch file that may do what you want:
setlocal enabledelayedexpansion
set output=
for /f "delims=" %%a in ('git diff --name-only %1^^') do ( set output=!output! "%%a" )
git archive -o update.zip HEAD %output%
endlocal
It works by collecting all lines of the output of the `git diff ...` command into an environment variable, and then using this to perform the `git archive ...` operation.
Documentation for the Windows `for` command is here, including the `/f` switch. Documentation for the `setlocal` command is here.
Problem
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 ```