# End-of-line comments are prompted with "is not a valid attribute name"

4 messages from 2023-12-13 to 2023-12-17. Participants: D无数, Junio C Hamano.
Thread: https://gitlist.dev/t/60613

## D无数, 2023-12-13 17:32

Subject: End-of-line comments are prompted with "is not a valid attribute name"
Message-ID: <CAOQ=bxz8txyOt6p5L0qfx5DFKfxUhWvHW0pJP+YTbWVfBpvYxg@mail.gmail.com>
URL: https://gitlist.dev/e/CAOQ%3Dbxz8txyOt6p5L0qfx5DFKfxUhWvHW0pJP%2BYTbWVfBpvYxg%40mail.gmail.com

```
> macos 13.5.2
> git version 2.37.0 (Apple Git-136)

I use end-of-line comments in my .gitattributes file, and it is often
(not always present, but often) prompted with '# is not a valid
attribute name: .gitattributes:1' when performing many operations.

This is my .gitattributes:
ˋˋˋ
res/csv/*.txt eol=lf # 保证csv为lf，以匹配解析格式

# Custom for Visual Studio
*.cs     diff=csharp
ˋˋˋ

When performing certain operations:
···shell
> git status
# is not a valid attribute name: .gitattributes:1
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
···

Other repositories that have .gitattributes files and include
end-of-line comments do the same thing. I'm sure there are no special
characters in my files.

```

## Junio C Hamano, 2023-12-13 19:22

Subject: Re: End-of-line comments are prompted with "is not a valid attribute name"
Message-ID: <xmqqsf45nbzm.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqsf45nbzm.fsf%40gitster.g
In-Reply-To: <CAOQ=bxz8txyOt6p5L0qfx5DFKfxUhWvHW0pJP+YTbWVfBpvYxg@mail.gmail.com>

```
D无数 <wushuripple@gmail.com> writes:

> This is my .gitattributes:
> ˋˋˋ
> res/csv/*.txt eol=lf # 保证csv为lf，以匹配解析格式

I do not think of any version of Git ignoring what you wrote after #
(including #) in the middle of the line.

> # Custom for Visual Studio

I know I designed the parser to allow this as a comment, though.

So

> When performing certain operations:
> ···shell
>> git status
> # is not a valid attribute name: .gitattributes:1

This is totally expected; nothing to see here.


```

## Junio C Hamano, 2023-12-17 17:15

Subject: Re: End-of-line comments are prompted with "is not a valid attribute name"
Message-ID: <xmqqo7eoiwcb.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqo7eoiwcb.fsf%40gitster.g
In-Reply-To: <xmqqsf45nbzm.fsf@gitster.g>

```
Junio C Hamano <gitster@pobox.com> writes:

> This is totally expected; nothing to see here.

To put it another way, we do not have "end-of-line comment"
(i.e. the leading part of a line has payload, but the line is
chomped in the middle with a comment character and the remainder of
the line is ignored) at all.  We have "commented line" (in other
words, a line that is totally commented out and gets ignored).

I think it is very clearly documented in "git help attributes":

    A `gitattributes` file is a simple text file that gives
    `attributes` to pathnames.

    Each line in `gitattributes` file is of form:

            pattern attr1 attr2 ...

    That is, a pattern followed by an attributes list,
    separated by whitespaces. Leading and trailing whitespaces are
    ignored. Lines that begin with '#' are ignored. Patterns
    that begin with a double quote are quoted in C style.


```

## D无数, 2023-12-17 17:28

Subject: Re: End-of-line comments are prompted with "is not a valid attribute name"
Message-ID: <CAOQ=bxyBVRJN68iLs7g=DjB+J7aHEFgwnGuhS_ub2=q3StiRkQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAOQ%3DbxyBVRJN68iLs7g%3DDjB%2BJ7aHEFgwnGuhS_ub2%3Dq3StiRkQ%40mail.gmail.com
In-Reply-To: <xmqqo7eoiwcb.fsf@gitster.g>

```
I see, thanks for the answer.
I was fooled by the VSCode highlighting, but also because I didn't try
to figure out the documentation carefully.

Junio C Hamano <gitster@pobox.com> 于2023年12月18日周一 01:15写道：
>
> Junio C Hamano <gitster@pobox.com> writes:
>
> > This is totally expected; nothing to see here.
>
> To put it another way, we do not have "end-of-line comment"
> (i.e. the leading part of a line has payload, but the line is
> chomped in the middle with a comment character and the remainder of
> the line is ignored) at all.  We have "commented line" (in other
> words, a line that is totally commented out and gets ignored).
>
> I think it is very clearly documented in "git help attributes":
>
>     A `gitattributes` file is a simple text file that gives
>     `attributes` to pathnames.
>
>     Each line in `gitattributes` file is of form:
>
>             pattern attr1 attr2 ...
>
>     That is, a pattern followed by an attributes list,
>     separated by whitespaces. Leading and trailing whitespaces are
>     ignored. Lines that begin with '#' are ignored. Patterns
>     that begin with a double quote are quoted in C style.
>

```
