13

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

4 Answers 4

6

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 ? )

Sign up to request clarification or add additional context in comments.

3 Comments

that's not bad actually. very very not bad. I like it
the only concern is that it might be a little slow for big patches(but that should not happen if you're deploying a lot of small patches) Also, what if there is a connection problem while you're applying a patch?
@TarasMankovski There is a bigger problem when applying git binary delta patch to big binary file(s).
2

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.

1 Comment

Hey Temoto, thank you for the answer, but I am looking for an answer that I don't already know.
2

According to the change log, we can expect patch versions > 2.6.1 to support GIT binary diffs.

3 Comments

patch 2.7.5 still doesn't on my system :(
The Changelog at git.savannah.gnu.org/cgit/patch.git/tree/NEWS doesn't seem to mention this either...
Actually it doesn't. And there is no sign of other patch(1) supports git binary diff at the moment.
-7

Use this

git apply example.patch
git add --patch
git commit

You can omit --patch flag, but you won't see every change and check patching process.

2 Comments

OK, I didn't get it exactly first. So if you have no Git on remote server, the only way is to copy modified binary files. As far as I know, 'patch' does not support binary diffs.
yes, standard patch does not support binary diffs, but git diff can generate binary patches. I would like to apply them without having git installed on remote server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.