git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: git@vger.kernel.org
Cc: eblake@redhat.com, j6t@kdbg.org, jrnieder@gmail.com, gitster@pobox.com
Subject: [PATCHv3 2/2] Documentation: enhance gitignore whitelist example
Date: Tue,  5 Apr 2011 16:17:58 -0600	[thread overview]
Message-ID: <1302041878-24426-2-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1302041878-24426-1-git-send-email-eblake@redhat.com>

I was trying to whitelist a single file pattern in a directory
that I was otherwise content to ignore, but when I tried:

  /m4/
  !/m4/virt-*.m4

then 'git add' kept warning me that I had to use -f.  I finally
figured out that ignoring a directory is much different than ignoring
all files in a directory, when it comes to later negation patterns:

  /m4/*
  !/m4/virt-*.m4

Improving the documentation will help others learn from my mistake.

CC: Jonathan Nieder <jrnieder@gmail.com>
CC: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Eric Blake <eblake@redhat.com>
---

v3: split out fnmatch tweaks, don't tweak specification of patterns
or existing examples but instead add an entirely new example, make
the example use a deeper hierarchy

 Documentation/gitignore.txt |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index 9b1e5e1..e1ad234 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -139,6 +139,44 @@ EXAMPLES
     [...]
 --------------------------------------------------------------

+It is possible to ignore most of a hierarchy, while still
+white-listing a single file, by ignoring multiple files then using a
+negation pattern for the file in question.  However, this requires
+ignoring files and not directories, since no patterns are ever matched
+inside of an ignored directory.  For nested files, it requires several
+iterations of refined patterns.
+
+--------------------------------------------------------------
+    $ git status
+    [...]
+    # Untracked files:
+    [...]
+    #       Documentation/build/file
+    #       build/file
+    #       build/foo/baz
+    #       build/foo/other
+    [...]
+    $ cat .gitignore
+    # Use anchoring, since `build' would ignore Documentation/build.
+    # Do not ignore the directory itself, ...
+    # /build/
+    # rather ignore files in the top-level build directory, ...
+    /build/*
+    # but permit child directories, ...
+    !/build/*/
+    # then ignore all nested files, ...
+    /build/*/*
+    # and finally white-list the special file
+    !/build/foo/baz
+    $ git status
+    [...]
+    # Untracked files:
+    [...]
+    #       Documentation/build/file
+    #       build/foo/baz
+    [...]
+--------------------------------------------------------------
+
 Another example:

 --------------------------------------------------------------
-- 
1.7.4

  reply	other threads:[~2011-04-05 22:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-05 22:17 [PATCHv3 1/2] Documentation: clarify fnmatch behavior in gitignore Eric Blake
2011-04-05 22:17 ` Eric Blake [this message]
2011-04-05 22:43   ` [PATCHv3 2/2] Documentation: enhance gitignore whitelist example Junio C Hamano
2011-04-05 22:34 ` [PATCHv3 1/2] Documentation: clarify fnmatch behavior in gitignore Junio C Hamano
2011-04-05 22:43   ` Eric Blake
2011-04-06 12:48     ` Drew Northup

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=1302041878-24426-2-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=jrnieder@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).