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

Re: [PATCH] Documentation: enhance gitignore whitelist example

From
Eric Blake <eblake@redhat.com>
Date
Apr 5, 2011, 21:49 UTC
Message-ID
<4D9B8E66.2010408@redhat.com>
In-Reply-To
<20110405214114.GA13729@elie>
On 04/05/2011 03:41 PM, Jonathan Nieder wrote:
Show 10 quoted lines
> Eric Blake wrote:
> 
>> Yeah, but then you have to 'git add -f path/to/file' them every time you
>> change them
> 
> No, I don't believe that's true.
> 
>  $ git add -f git.o
>  $ >git.o
>  $ git add git.o
Aha - it's that pesky dir/ vs. dir/* biting me, yet again:
$ mkdir -p /tmp/blah
$ cd /tmp/blah
$ git init
Initialized empty Git repository in /tmp/blah/.git/
$ mkdir sub
$ > sub/file
$ git add sub/file
$ git commit -a -m 'one'
[master (root-commit) 645ee5a] one
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 sub/file
$ printf 'sub/*\n!sub/file\n' > .gitignore
$ touch sub/file2
$ echo hi > sub/file
$ 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:   sub/file
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	.gitignore
no changes added to commit (use "git add" and/or "git commit -a")
$ git add sub
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	modified:   sub/file
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	.gitignore
$ git reset
Unstaged changes after reset:
M	sub/file
$ printf 'sub/\n!sub/file\n' > .gitignore
$ git add sub
The following paths are ignored by one of your .gitignore files:
sub
Use -f if you really want to add them.
fatal: no files added
$ git add sub/file
The following paths are ignored by one of your .gitignore files:
sub
Use -f if you really want to add them.
fatal: no files added
$ 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:   sub/file
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	.gitignore
no changes added to commit (use "git add" and/or "git commit -a")
$ git add .
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	new file:   .gitignore
#	modified:   sub/file
#
> 
> .gitignore only protects against starting to track a file that was
> previously untracked.

Not quite. When filtering a directory, it also protects against changes to tracked files in that directory. And that is what has been throwing me off, which is why we need a doc change (or possibly even a behavior change).

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org
Previous: Jonathan NiederNext: Junio C Hamano
Message 6 of 9 in “Documentation: enhance gitignore whitelist example”
  1. Documentation: enhance gitignore whitelist exampleEric Blake, Apr 5, 2011
  2. Jonathan NiederApr 5, 2011
  3. Johannes SixtApr 5, 2011
  4. Eric BlakeApr 5, 2011
  5. Jonathan NiederApr 5, 2011
  6. Eric BlakeApr 5, 2011
  7. Junio C HamanoApr 5, 2011
  8. Junio C HamanoApr 5, 2011
  9. Junio C HamanoApr 5, 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.