git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Behaviour of git apply --directory

From
ABAndrew Berry <andrewberry@sentex.net>
Date
Aug 24, 2011, 14:26 UTC
Message-ID
<5FC87CBA-13C9-4FAD-80C1-66B3550C9EBB@sentex.net>
In-Reply-To
<7vfwktwbbb.fsf@alter.siamese.dyndns.org>
Thanks for your detailed explanation.
On 2011-08-22, at 2:28 PM, Junio C Hamano wrote:
> 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.
This is where I see the issue. For some reason when I specify --directory, I do have to be somewhere in the directory tree that the patch is going to be applied to. For example, in the following it works if my cwd is the repository root, or src, but not patches.

$ find . -not -path '*.git*' . ./patches ./patches/LICENSE.patch ./src ./src/LICENSE.txt $ git status # On branch master nothing to commit (working directory clean) $ cat patches/LICENSE.patch

diff --git a/LICENSE.txt b/LICENSE.txt
index 2c095c8..64ee213 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,3 +1,4 @@
+GPL GPL GPL
 GNU GENERAL PUBLIC LICENSE
 
               Version 2, June 1991
$ cd patches
$ git apply -v --directory=src LICENSE.patch
$ git status
# On branch master
nothing to commit (working directory clean)
$ cd ..
$ git apply -v --directory=src patches/LICENSE.patch
Checking patch src/LICENSE.txt...
Applied patch src/LICENSE.txt cleanly.
$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   src/LICENSE.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git checkout src
$ cd src
$ git apply -v --directory=src ../patches/LICENSE.patch
Checking patch src/LICENSE.txt...
Applied patch src/LICENSE.txt cleanly.
$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   LICENSE.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
Previous: Junio C Hamano
Message 3 of 3 in “Behaviour of git apply --directory”
  1. Andrew BerryAug 22, 2011
  2. Junio C HamanoAug 22, 2011
  3. Andrew BerryAug 24, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.