10

Either i'm going nuts or nobody likes/liked this feature, but a long time ago i used to use subversion with sourceforge system. I had the ability to create full file patches for commits done.

I cannot figure out anyway to create these in git, all i want is the files that were changed from XX commit and only those files in their entirety so that i could hand them off to someone/upload just those files to a location.

As it currently stands i'm stuck reuploading the entire project because i have nothing that tells me what was changed. Since we're also on a shared web host there is no way to get git on the server without upgrading to more expensive package.

I've tried

git archive --output=/home/username/temp.zip <commit id>

which put everything into a zip nicely but it did just that, it put everything. Also tried a variation of format-patch but that didn't seem to work.

iarp
  • 546
  • 1
  • 9
  • 20

2 Answers2

18

It seems that I misunderstood what you wanted in my other answer. git archive can take a list of paths to include in the archive, so you could do:

git archive -o /tmp/foo.zip HEAD $(git diff --name-only oldcommit HEAD)

If your filenames contain surprising characters, though, it would be safer to do:

git diff -z --name-only oldcommit HEAD | xargs -0 git archive HEAD -o /tmp/blah.zip --
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • 1
    Thanks, this worked. In my case I needed it again a branch instead of commit. So I did: `git diff -z --name-only origin/branch_name | xargs -0 git archive HEAD -o /tmp/blah.zip`, and then applied those changes by extracting file in my repo: `tar -xf /tmp/blah.zip` – Surya Jun 11 '15 at 12:34
4

The first thing to try would be to save the output of git diff, which might be sufficient in your situation:

git diff oldcommit > test.patch

If you have changed binary files since then, you could try:

git diff --binary oldcommit > test-with-binaries.patch

In that case you'd then need to apply the patch with git apply. Otherwise, I would create a new branch based on oldcommit, do a squashed merge from master, commit the result and and use git format-patch to produce the patch. That method (and several other solutions to your problem) are described in more detail in the answers to this similar stackoverflow question: How do you squash commits into one patch with git format-patch?

Community
  • 1
  • 1
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • That still only outputs the section that was changed, i need the whole files in their entirety. If i changed 2 lines on config.inc i want the entire config.inc not just the changed lines. – iarp Feb 11 '11 at 15:00
  • @iarp: Ah, OK - sorry. I've added another answer with a different suggestion that uses `git archive` instead. – Mark Longair Feb 11 '11 at 15:14