Export Changed Files Between Two Commits

git archive --output=package.zip update_commit $(git diff --name-only original_commit..update_commit --diff-filter=d)
| — folder1
| | — file1.txt
| — file2.txt
## file1.txt has the following content:
this is file 1
## file2.txt has the following content:
this is file 2

## this is what file1.txt looks like after the second commit
this is file 1
update file1.txt

## this is what file2.txt looks like after the third commit
this is file 2
update file2.txt

c2505fe (HEAD -> master) update file2
c780650 update file1
f3f57c9 initial commit

Generate the list of new and modified files

The first half of the command obtains a list of all new or modified files between two commits. Since we know the starting point is the commit with ID f3f57c9 and the ending point is HEAD, we can have our first half:

git diff --name-only f3f57c9..HEAD --diff-filter=d

Archive the generated files

We have the list of files to be archived now. We will then use the list of files for the second half of the command to create the zip file.

git archive --output=deployment-v1.zip HEAD $(git diff --name-only f3f57c9..HEAD --diff-filter=d)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Teng Wei Song

Teng Wei Song

My journey as a self-taught developer. Feel free to drop by my online profile at tengweisong.com as well!