9

I need to make a patch for someone (they are not using git) - a zip of the files changed by a commit.

I thought something like

git archive --format=zip commitguid > myfiles.zip

but this extracts the entire thing, not just the changed files. Is there any way to do this? And to make it more complicated - is there any way of doing this with multiple commits (yes I should have branched before making the changes but that's hindsight)

EDIT

Based on @Amber solution below I can do this in 2 steps in Git Bash for windows with 7Zip installed in c:\data\progs.

git diff --name-only a-sha b-sha > tmp.txt
/C/data/progs/7za.exe a myzip.zip @tmp.txt
Andiih
  • 12,285
  • 10
  • 57
  • 88

3 Answers3

19
git diff --name-only <oldsha> <newsha> | zip dest.zip -@

filling in the proper SHAs/refs. For instance, to create a zip of only the files that changed between the master and feature branches:

git diff --name-only master feature | zip dest.zip -@
Amber
  • 507,862
  • 82
  • 626
  • 550
  • Thanks Amber. Any ideas how to get this to work on windows with only 7-zip installed ? I'm trying (the 2nd half of your command) | /C/progs/7za.exe a myzip.zip -@ but get Error: Incorrect command line – Andiih May 29 '12 at 18:23
  • 2
    You can do it in one step with the 7-zip `-si` flag: http://pwet.fr/man/linux/commandes/7z and http://stackoverflow.com/questions/805706/piping-data-on-windows-command-prompt – ellotheth May 29 '12 at 20:49
  • This is nice but can you explain the `-@` part? – Eric MORAND Dec 10 '18 at 10:32
  • 1
    @EricMORAND If a file list is specified as `-@`, `zip` takes the list of input files from standard input instead of from the command line. – Amber Dec 16 '18 at 20:02
1

See also git help format-patch. It produces a diff patch of all changes in a commit along with commit author, date, message, and some nice diff stats. You could zip and send that.

ulidtko
  • 14,740
  • 10
  • 56
  • 88
0

I found this solution to the question (on github-gist, from user rmkpatchaa).
It doesn't require any external tools and is a one line command in a windows Git Bash window:

git archive --output=changes.zip HEAD $(git diff --name-only SHA1 SHA2 --diff-filter=ACMRTUXB)

It creates a standard zip archive with only the files changed between the two commits, no extra git stuff or anything, and doesn't require any extra tool on the receiving side.

K.Isbruch
  • 145
  • 2
  • 8
  • Good option and can be applied on Windows systems without zip. But it would be great to elaborate in answer - what the purpose options "HEAD" and "--diff-filter=ACMRTUXB" – Vladimir Oct 26 '19 at 15:19