git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git add <single file> and git add <list of files> behave differentely for ignored files
@ 2014-12-04  9:06 Guilherme
  2014-12-04 11:11 ` Konstantin Khomoutov
  2014-12-04 15:02 ` Michael J Gruber
  0 siblings, 2 replies; 7+ messages in thread
From: Guilherme @ 2014-12-04  9:06 UTC (permalink / raw)
  To: git@vger.kernel.org

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 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.

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: git add <single file> and git add <list of files> behave differentely for ignored files
  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
  1 sibling, 1 reply; 7+ messages in thread
From: Konstantin Khomoutov @ 2014-12-04 11:11 UTC (permalink / raw)
  To: Guilherme; +Cc: git

On Thu, 4 Dec 2014 10:06:23 +0100
Guilherme <guibufolo@gmail.com> wrote:

> 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>`.
[...]

To those who's interested the original thread on git-users is
https://groups.google.com/d/topic/git-users/322tole9am8/discussion

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: git add <single file> and git add <list of files> behave differentely for ignored files
  2014-12-04 11:11 ` Konstantin Khomoutov
@ 2014-12-04 11:49   ` Guilherme
  0 siblings, 0 replies; 7+ messages in thread
From: Guilherme @ 2014-12-04 11:49 UTC (permalink / raw)
  To: Konstantin Khomoutov; +Cc: git

I forgot to mention:

Environment: Cygwin

Git version 2.1.1

On Thu, Dec 4, 2014 at 12:11 PM, Konstantin Khomoutov
<flatworm@users.sourceforge.net> wrote:
> On Thu, 4 Dec 2014 10:06:23 +0100
> Guilherme <guibufolo@gmail.com> wrote:
>
>> 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>`.
> [...]
>
> To those who's interested the original thread on git-users is
> https://groups.google.com/d/topic/git-users/322tole9am8/discussion

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: git add <single file> and git add <list of files> behave differentely for ignored files
  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 15:02 ` Michael J Gruber
  2014-12-04 15:23   ` [PATCH] check-ignore: clarify treatment of tracked files Michael J Gruber
  1 sibling, 1 reply; 7+ messages in thread
From: Michael J Gruber @ 2014-12-04 15:02 UTC (permalink / raw)
  To: Guilherme, git@vger.kernel.org

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] check-ignore: clarify treatment of tracked files
  2014-12-04 15:02 ` Michael J Gruber
@ 2014-12-04 15:23   ` Michael J Gruber
  2014-12-04 20:15     ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Michael J Gruber @ 2014-12-04 15:23 UTC (permalink / raw)
  To: git; +Cc: Guilherme

By default, check-ignore does not list tracked files at all since
they are not subject to ignore patterns.

Make this clearer in the man page.

Reported-by: Guilherme <guibufolo@gmail.com>
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
That really is a bit confusing. Does this help?

 Documentation/git-check-ignore.txt | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/git-check-ignore.txt b/Documentation/git-check-ignore.txt
index ee2e091..788a011 100644
--- a/Documentation/git-check-ignore.txt
+++ b/Documentation/git-check-ignore.txt
@@ -21,6 +21,9 @@ the exclude mechanism) that decides if the pathname is excluded or
 included.  Later patterns within a file take precedence over earlier
 ones.
 
+By default, tracked files are not shown at all since they are not
+subject to exclude rules; but see `--no-index'.
+
 OPTIONS
 -------
 -q, --quiet::
-- 
2.2.0.rc3.286.g888a711

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] check-ignore: clarify treatment of tracked files
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2014-12-04 20:15 UTC (permalink / raw)
  To: Michael J Gruber; +Cc: git, Guilherme

Michael J Gruber <git@drmicha.warpmail.net> writes:

> By default, check-ignore does not list tracked files at all since
> they are not subject to ignore patterns.
>
> Make this clearer in the man page.
>
> Reported-by: Guilherme <guibufolo@gmail.com>
> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
> ---
> That really is a bit confusing. Does this help?

Thanks.

"git check-ignore" is a tool to debug your .gitignore settings when
your expectation does not match the reality, so having this new
sentence here is a good thing to do, but I wonder if there is a more
prominent and central place where people learn about the ignore
mechanism the first place.  If we had this sentence there, too, that
may reduce the need to debug their .gitignore settings in the first
place.

Perhaps Documentation/gitignore.txt?  Documentation/user-manual.txt?


>
>  Documentation/git-check-ignore.txt | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/Documentation/git-check-ignore.txt b/Documentation/git-check-ignore.txt
> index ee2e091..788a011 100644
> --- a/Documentation/git-check-ignore.txt
> +++ b/Documentation/git-check-ignore.txt
> @@ -21,6 +21,9 @@ the exclude mechanism) that decides if the pathname is excluded or
>  included.  Later patterns within a file take precedence over earlier
>  ones.
>  
> +By default, tracked files are not shown at all since they are not
> +subject to exclude rules; but see `--no-index'.
> +
>  OPTIONS
>  -------
>  -q, --quiet::

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] check-ignore: clarify treatment of tracked files
  2014-12-04 20:15     ` Junio C Hamano
@ 2014-12-08 16:13       ` Michael J Gruber
  0 siblings, 0 replies; 7+ messages in thread
From: Michael J Gruber @ 2014-12-08 16:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Guilherme

Junio C Hamano schrieb am 04.12.2014 um 21:15:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
> 
>> By default, check-ignore does not list tracked files at all since
>> they are not subject to ignore patterns.
>>
>> Make this clearer in the man page.
>>
>> Reported-by: Guilherme <guibufolo@gmail.com>
>> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
>> ---
>> That really is a bit confusing. Does this help?
> 
> Thanks.
> 
> "git check-ignore" is a tool to debug your .gitignore settings when
> your expectation does not match the reality, so having this new
> sentence here is a good thing to do, but I wonder if there is a more
> prominent and central place where people learn about the ignore
> mechanism the first place.  If we had this sentence there, too, that
> may reduce the need to debug their .gitignore settings in the first
> place.
> 
> Perhaps Documentation/gitignore.txt?  Documentation/user-manual.txt?

gitignore.txt has

DESCRIPTION
       A gitignore file specifies intentionally untracked files that Git
should ignore. Files already tracked by Git are not affected; see the
       NOTES below for details.

I doesn't get any clearer. But then the notes read:

NOTES
       The purpose of gitignore files is to ensure that certain files
not tracked by Git remain untracked.

       To ignore uncommitted changes in a file that is already tracked,
use git update-index --assume-unchanged.

       To stop tracking a file that is currently tracked, use git rm
--cached.

That is again clear for our case (line 1), but line 2 is troublesome,
isn't it?

user-manual mainly refers to gitignore. So I guess it's good, but that
line about assume-unchanged doesn't quite match with the discussion in
another current thread.

Michael

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-12-08 16:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).