Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply git diff --binary patches without git installed?

I use to git diff to generate patches that can be applied to remote server to update a project.

Locally, I run:

git diff --no-prefix HEAD~1 HEAD > example.patch

Upload example.patch to remote server and run:

patch --dry-run -p0 < example.patch

If dry-run is successful, I run:

patch -p0 < example.patch

This works well, except when diff includes binary files. Today, I found that I can use:

git diff --no-prefix --binary HEAD~1 HEAD > example.patch

The problem is that the generated patch file can not be applied using patch.

How can I apply these binary patch files without having git installed the server?

I would like to maintain ability to use dry-run.

Thank you

like image 357
Taras Mankovski Avatar asked Dec 15 '09 21:12

Taras Mankovski


People also ask

What is git apply?

git apply takes a patch (e.g. the output of git diff ) and applies it to the working directory (or index, if --index or --cached is used). git am takes a mailbox of commits formatted as an email messages (e.g. the output of git format-patch ) and applies them to the current branch.

What is Patch file in git?

Patch is a text file, whose contents are similar to Git diff, but along with code, it also has metadata about commits; e.g., commit ID, date, commit message, etc. We can create a patch from commits and other people can apply them to their repository.


2 Answers

For an outlandish answer, what you could do is use sshfs to mount the remote system upon where ever you do have git, and then run your commands that way. Approach the problem from a different frame of reference: Instead of wondering how to run commands where the tool is not, why not create an environment where the data comes to your tool ( via sshfs ? )

like image 65
chiggsy Avatar answered Oct 20 '22 19:10

chiggsy


In many situations and in this too, you can't create data with more advanced tool and use it with less advanced. It's a happy coincidence that patch works for non-binary git-diffs. git diff introduces an extension to standard diff.

To achieve the goal, you can:

  • install git on the destination system (that's the best approach, really)
  • mount destination system to local, as chiggsy says
  • just scp/rsync new files. Not bad for small ones.
like image 43
temoto Avatar answered Oct 20 '22 17:10

temoto