Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipe git diff to git apply

Tags:

git

shell

patch

zsh

Why won't this command work ?

git diff | git --git-dir=/other/location/.git --work-tree=/other/location apply

The following works perfectly:

git diff > /tmp/my.patch
cd /other/location && git apply /tmp/my.patch

/other/location is a mirror of the current directory.

With the piped command I get

error: patch failed: myfile.php:1
error: myfile.php: patch does not apply
like image 749
Alasdair Avatar asked Nov 12 '15 11:11

Alasdair


1 Answers

This works for me (git 2.6.3):

git diff | git -C /other/location apply

From man git:

-C <path>
       Run as if git was started in <path> instead of the current working
       directory. When multiple -C options are given, each subsequent 
       non-absolute -C <path> is interpreted relative to
       the preceding -C <path>.
like image 100
Alexey Shein Avatar answered Oct 06 '22 22:10

Alexey Shein