Using Git to create an archive of changed files
I'm using this answer in that case that tells me to
tar czf changed-files.tar.gz `git diff --name-only [diff options]`
For example, to create an archive containing the files changed in the last four revisions, I'd do
tar czf changed-files.tar.gz `git diff --name-only HEAD~4..`
This assumes – of course – that HEAD~4
does actually exist.
You just need to filter out files deleted while that diff to fix that error:
git archive -o update.zip HEAD $(git diff --name-only --diff-filter=d HEAD^..HEAD)
May be git archive
is overhead for that task and you should use @eckes's answer.
But, you still should add --diff-filter=d
to exclude removed files from archive.
I use this alias to include new files not in HEAD:
alias gittar='tar -czvf working-files.tgz \
$(git status -s | sed -r "s/..(.*)/\1 /")'