git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael J Gruber <git@drmicha.warpmail.net>
To: Guilherme <guibufolo@gmail.com>,
	"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: git add <single file> and git add <list of files> behave differentely for ignored files
Date: Thu, 04 Dec 2014 16:02:21 +0100	[thread overview]
Message-ID: <5480777D.6000205@drmicha.warpmail.net> (raw)
In-Reply-To: <CAMDzUtzQJoEi17OfX8FPOV6SDJ_ytJSH-YTKx2DtUON35-EVSg@mail.gmail.com>

Guilherme schrieb am 04.12.2014 um 10:06:
> Hello,
> 
> I reported this issue on the git-user mailing list and they redirected me here.
> 
> The problem I have observed is that with a ignored path `git add
> <single file>` behaves differently then `git add <list of files>`.
> 
> I my git/info/excludes file i have
> 
> /COM/config
> !COM/config/Project.gny
> 
> The file COM/config/Project.gny has already been added to the
> repository via `git add -f`.
> 
> When doing
> 
>     git add -- COM/config/Projec.gny
> 
> git will not complain but when doing
> 
>     git add -- COM/config/Project.gny otherfiles.c
> 
> it will report:
> 
>     The following paths are ignored by one of your .gitignore files:
>     COM/config
>     Use -f if you really want to add them.
>     fatal: no files added

This is because git add assumes you specified on of the files in error,
and thus refuses to add the other one, too.

I found that behaviour surprising. There's already a patch which, in the
2nd case, would make "git add" only warn you about the ignored file but
add the other one anyways. It will probably make its way into the next
release.

For the case of a single file (or rather: ignored files only) I'm
wondering whether we should issue a warning, too.

> This odd behaviour is also present in `git check-ignore`.
> 
> Before adding the file `git check-ignore` correctly reports the file
> as ignored. After having added it via `git add -f` it won't report it
> as ignored anymore.

This is different: Once a file is "added", it is not ignored any more -
you explicitely told git to track that file (rather than ignoring it).
So, the output of git check-ignore is correct.

> Even if not a bug this behaviour is inconsistent and might want to be
> addressed as it makes scripting a little bit harder.
> 
> Thank you.
> 

I guess you want "git check-ignore --no-index". That man page may be a
bit misleading - the description sounds as if only the patterns would
matter.

Michael

  parent reply	other threads:[~2014-12-04 15:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-04  9:06 git add <single file> and git add <list of files> behave differentely for ignored files Guilherme
2014-12-04 11:11 ` Konstantin Khomoutov
2014-12-04 11:49   ` Guilherme
2014-12-04 15:02 ` Michael J Gruber [this message]
2014-12-04 15:23   ` [PATCH] check-ignore: clarify treatment of tracked files Michael J Gruber
2014-12-04 20:15     ` Junio C Hamano
2014-12-08 16:13       ` Michael J Gruber

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=5480777D.6000205@drmicha.warpmail.net \
    --to=git@drmicha.warpmail.net \
    --cc=git@vger.kernel.org \
    --cc=guibufolo@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).