Skip to content

Instantly share code, notes, and snippets.

@sawwd
Created May 30, 2018 17:39
Show Gist options
  • Save sawwd/f58367e34709b2aba99b908c24eb2de7 to your computer and use it in GitHub Desktop.
Save sawwd/f58367e34709b2aba99b908c24eb2de7 to your computer and use it in GitHub Desktop.
Git: archive only the changes between two commits.
#!/bin/bash
IFS=$'\n'
files=($(git diff --name-only $1 $2))
git archive -o $3 $2 "${files[@]}"
@sawwd
Copy link
Author

sawwd commented May 30, 2018

In the working directory:

Running git log --pretty=oneline

Will output something like:

ddd9b0d0e4ab886b9ef23f6c04856382b4c48546 (HEAD -> master, origin/master) Last commit
30c92c6b16d578266722f2199c0ea577da103efe Third commit
0971975c68d49485119008c96b5ccf24063b4651 Second commit
359592c2075947e957e3455a1885e12dafa0df63 Fist commit

Type q to exit from git log.

Let's say we want to make an archive only with the file changes between 359592 (first commit SHA1) and ddd9b0d (last commit SHA1) named last-changes.zip

We will run:

./gitdiffzip.sh 359592 ddd9b0d last-changes.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment