threads / patch / 21707

patch, 4 partsapply: apply works outside a repository

Subject: [PATCH 2/4] apply: apply works outside a repository

## tl;dr

2 messages between Nov 22, 2009 and Nov 22, 2009. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Björn Gustavsson· Nov 22, 2009, 16:19 UTC · lore

The documentation for 'git apply' talks about applying a patch/diff to the index and to the working tree, which seems to imply that it will not work outside a git repository.

Actually 'git patch' works outside a repository (which can be useful especially for applying binary or rename patches that the standard "patch" utility cannot handle), so the documentation should mention it.

Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com>
---
 Documentation/git-apply.txt |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Show changes to Documentation/git-apply.txt +4 −0
diff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt
index 4f791ee..6857a68 100644
--- a/Documentation/git-apply.txt
+++ b/Documentation/git-apply.txt
@@ -23,6 +23,10 @@ DESCRIPTION
 Reads supplied 'diff' output and applies it on a git index file
 and a work tree.
 
+'git-apply' can also be used outside a git repository as long
+as no options that require a git repository are given
+(e.g. `--index` or `--cached`).
+
 OPTIONS
 -------
 <patch>...::
-- 
1.6.5.3.298.g39add
Junio C Hamano· Nov 22, 2009, 17:28 UTC · re: Björn Gustavsson · lore

Re: [PATCH 2/4] apply: apply works outside a repository

Björn Gustavsson <bgustavsson@gmail.com> writes:
> The documentation for 'git apply' talks about applying a
> patch/diff to the index and to the working tree, which seems
> to imply that it will not work outside a git repository.

Thanks. I think the headline should also be reworded. It currently reads:

    Apply a patch on a git index file and/or a working tree

but historically and still in real life practices, when you use apply (as opposed to am), you apply primarily to the files and optionally to the index, so this should read something like:

    Apply a patch to files and/or to the index

We could say "to files in the work tree", but that would give a wrong impression that the files we talk about must be in a directory that is part of the work tree of some repository, so it probably is better without it.

The same comment applies to the beginning of the DESCRIPTION section. I actually think your added text should reword the current two-liner there, instead of being added at the bottom. Here is my attempt.

    Reads supplied diff output (iow "a patch"), and applies it to files.
    With --index (--cache) options, the patch is also (only) applied to
    the index respectively.  Without these options, the command applies
    the patch only to files, and does not require them to be in a git
    repository.

← back to recent threads