From: Junio C Hamano <gitster@pobox.com>
To: Andrew Berry <andrewberry@sentex.net>
Cc: git@vger.kernel.org
Subject: Re: Behaviour of git apply --directory
Date: Mon, 22 Aug 2011 11:28:08 -0700 [thread overview]
Message-ID: <7vfwktwbbb.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <E21BC0F8-2DF0-44AB-B18A-013451CDB670@sentex.net> (Andrew Berry's message of "Mon, 22 Aug 2011 11:21:55 -0400")
Andrew Berry <andrewberry@sentex.net> writes:
> The behaviour of git apply --directory seems a little confusing. It
> looks to be dependent on the current directory, but I can't use relative
> paths to apply a patch in one directory to a sibling directory. Absolute
> paths don't work either. I'd expected the parameter to either be
> relative to the git repository root, or to expand relative directories.
I do not think that parameter does not have anything to do with your
cwd. As the documentation says:
--directory=<root>::
Prepend <root> to all filenames. If a "-p" argument was also passed,
it is applied before prepending the new root.
For example, a patch that talks about updating `a/git-gui.sh` to `b/git-gui.sh`
can be applied to the file in the working tree `modules/git-gui/git-gui.sh` by
running `git apply --directory=modules/git-gui`.
the parameter is just a fixed string that is used to modify the path that
appears in the patch before it gets applied, and has nothing to do with
your current (or previous for that matter) working directory.
Suppose you have a patch that tries to update "COPYING". Such a patch
generated by Git would look like this:
diff --git a/COPYING b/COPYING
index 536e555..ee559b1 100644
--- a/COPYING
+++ b/COPYING
@@ -1,3 +1,4 @@
+GPL GPL GPL
Note that the only valid version of the GPL as far as this project
is concerned is _this_ particular version of the license (ie v2, not
Further suppose that you have already rearranged your project so that that
file appears in licenses/gpl directory, and your $(cwd) is licenses/
subdirectory of your working tree.
You would give --directory=licenses/gpl/ without passing any custom -p
parameter. This internally turns the patch being applied into something
like:
diff --git a/licenses/gpl/COPYING b/licenses/gpl/COPYING
index 536e555..ee559b1 100644
--- a/licenses/gpl/COPYING
+++ b/licenses/gpl/COPYING
@@ -1,3 +1,4 @@
+GPL GPL GPL
Note that the only valid version of the GPL as far as this project
is concerned is _this_ particular version of the license (ie v2, not
Because the patch application in git is always relative to the top level
of your working tree no matter where you are, this applies to the path you
intended it to.
Here is a sample transcript to try it yourself.
$ (echo GPL GPL GPL; cat COPYING) >x && cat x >COPYING
$ git diff >P.diff
$ git checkout COPYING
$ mkdir -p licenses/gpl
$ git mv COPYING licenses/gpl
$ cd licenses
$ git apply -v --directory=licenses/gpl ../P.diff
Checking patch licenses/gpl/COPYING...
Applied patch licenses/gpl/COPYING cleanly.
$ git diff
diff --git a/licenses/gpl/COPYING b/licenses/gpl/COPYING
index 536e555..ee559b1 100644
--- a/licenses/gpl/COPYING
+++ b/licenses/gpl/COPYING
@@ -1,3 +1,4 @@
+GPL GPL GPL
Note that the only valid version of the GPL as far as this project
is concerned is _this_ particular version of the license (ie v2, not
next prev parent reply other threads:[~2011-08-22 18:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-22 15:21 Behaviour of git apply --directory Andrew Berry
2011-08-22 18:28 ` Junio C Hamano [this message]
2011-08-24 14:26 ` Andrew Berry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vfwktwbbb.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=andrewberry@sentex.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox