Pipe git diff to git apply

时间:2015-11-12 11:29:37

标签: git shell zsh patch

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

1 个答案:

答案 0 :(得分:9)

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>.