"git diff" doesn't respect gitattributes file on a bare repo #14180

Open
opened 2025-11-02 11:05:28 -06:00 by GiteaMirror · 10 comments
Owner

Originally created by @Shuenhoy on GitHub (Feb 24, 2025).

Description

At 1.22, this .gitattributes file can exclude files from diff.

**/3rd/** -diff linguist-vendored

However, it does not after 1.23.


Update: it's not related to Gitea's version, but bare repo or not.

Screenshots

1.22.6:

Image

1.23:

Image

How are you running Gitea?

https://gitea.com/Shuenhoy/demo

Originally created by @Shuenhoy on GitHub (Feb 24, 2025). ### Description At 1.22, this `.gitattributes` file can exclude files from diff. ``` **/3rd/** -diff linguist-vendored ``` However, it does not after 1.23. ---- Update: it's not related to Gitea's version, but bare repo or not. ### Screenshots <details> 1.22.6: ![Image](https://github.com/user-attachments/assets/13f6399d-3aa8-4a9c-9f73-6c3f667977dc) 1.23: ![Image](https://github.com/user-attachments/assets/0b6d11ba-fdfb-4e5e-bbbd-ee572a2540d1) </details> ### How are you running Gitea? https://gitea.com/Shuenhoy/demo
GiteaMirror added the type/proposaltype/upstreamissue/workaround labels 2025-11-02 11:05:28 -06:00
Author
Owner

@wxiaoguang commented on GitHub (Mar 27, 2025):

I have tried 1.22.6. I am unable to reproduce the "old behavior" you described:

Image

@wxiaoguang commented on GitHub (Mar 27, 2025): I have tried 1.22.6. I am unable to reproduce the "old behavior" you described: <details> ![Image](https://github.com/user-attachments/assets/65fff547-842b-4a90-ac6a-8a252e80ce6f) </details>
Author
Owner

@wxiaoguang commented on GitHub (Mar 27, 2025):

By the way, if I understand correctly, the "Binary file not show" is controlled by "IsBin" variable. Actually "IsBin" is not related to "linguist-vendored". You could take a look at the "IsBin" related logic, not too much

Image

Image

@wxiaoguang commented on GitHub (Mar 27, 2025): By the way, if I understand correctly, the "Binary file not show" is controlled by "IsBin" variable. Actually "IsBin" is not related to "linguist-vendored". You could take a look at the "IsBin" related logic, not too much <details> ![Image](https://github.com/user-attachments/assets/f995fb23-cbdf-4167-a41b-24292f1bc048) ![Image](https://github.com/user-attachments/assets/98e3eae7-ead5-4f6a-80a2-3c1a218e5a49) </details>
Author
Owner

@Shuenhoy commented on GitHub (Mar 27, 2025):

@wxiaoguang Thanks for the reply. I have sent you a PM of a link of my 1.22.6 demo site on Discord.

As for "linguist-vendored", it is unrelated here. The diff is excluded due to -diff.

Image

Image

@Shuenhoy commented on GitHub (Mar 27, 2025): @wxiaoguang Thanks for the reply. I have sent you a PM of a link of my 1.22.6 demo site on Discord. As for "linguist-vendored", it is unrelated here. The diff is excluded due to `-diff`. <details> ![Image](https://github.com/user-attachments/assets/12b80eeb-ab77-4738-ad04-2b46d57e43a7) ![Image](https://github.com/user-attachments/assets/1cd91b12-b638-4d21-8a68-947d94406898) </details>
Author
Owner

@wxiaoguang commented on GitHub (Mar 27, 2025):

I have cloned your repo. Still not reproducible.

The "diff" result is provided by git command.

Left is yours. Right is the one I cloned from yours (they have the same content and commit IDs)

Image

@wxiaoguang commented on GitHub (Mar 27, 2025): I have cloned your repo. Still not reproducible. The "diff" result is provided by git command. Left is yours. Right is the one I cloned from yours (they have the same content and commit IDs) <details> ![Image](https://github.com/user-attachments/assets/db7e6424-c789-4384-bdb7-1f95b2309da0) </details>
Author
Owner

@wxiaoguang commented on GitHub (Mar 27, 2025):

OK, I think I can understand the problem now.

It is related to "bare repo".

On a bare repo, the git diff doesn't respect "gitattributes" file.

@wxiaoguang commented on GitHub (Mar 27, 2025): OK, I think I can understand the problem now. It is related to "bare repo". On a bare repo, the `git diff` doesn't respect "gitattributes" file.
Author
Owner

@wxiaoguang commented on GitHub (Mar 27, 2025):

As a workaround for your case, you could set up a "global gitattributes file" for Gitea's git, for exmaple: https://stackoverflow.com/questions/28026767/where-should-i-place-my-global-gitattributes-file

More background: git on Gitea ignores the repo's .gitattributes and uses its own #8394

@wxiaoguang commented on GitHub (Mar 27, 2025): As a workaround for your case, you could set up a "global gitattributes file" for Gitea's git, for exmaple: https://stackoverflow.com/questions/28026767/where-should-i-place-my-global-gitattributes-file More background: git on Gitea ignores the repo's .gitattributes and uses its own #8394
Author
Owner

@Shuenhoy commented on GitHub (Mar 27, 2025):

Thanks for the explanation!

I am not fully sure about the behaviors of bare repo, e.g. why our instance / my demo instance (both deployed by docker) do not use bare repo before 1.23 (#8394 suggests gitea uses bare repo long time ago).

However, global gitattributes do not seem to be a valid workaround for our case, as there are a large number of repos. Such global config may break something unexpectedly. If the previous behaviors cannot be configured back due to some underlying code changes. I wonder if it is possible to support something like copying .gitattributes from main to .git/info/attributes mentioned in #8394.

@Shuenhoy commented on GitHub (Mar 27, 2025): Thanks for the explanation! I am not fully sure about the behaviors of bare repo, e.g. why our instance / my demo instance (both deployed by docker) do not use bare repo before 1.23 (#8394 suggests gitea uses bare repo long time ago). However, global gitattributes do not seem to be a valid workaround for our case, as there are a large number of repos. Such global config may break something unexpectedly. If the previous behaviors cannot be configured back due to some underlying code changes. I wonder if it is possible to support something like copying `.gitattributes` from main to `.git/info/attributes` mentioned in #8394.
Author
Owner

@wxiaoguang commented on GitHub (Mar 27, 2025):

I wonder if it is possible to support something like copying .gitattributes from main to .git/info/attributes mentioned in #8394.

I think it is feasible, if some people would like to implement it.

@wxiaoguang commented on GitHub (Mar 27, 2025): > I wonder if it is possible to support something like copying `.gitattributes` from main to `.git/info/attributes` mentioned in [#8394](https://github.com/go-gitea/gitea/issues/8394). I think it is feasible, if some people would like to implement it.
Author
Owner

@lunny commented on GitHub (Mar 27, 2025):

In bare repositories if you want to adjust the gitattributes file you need to edit the .git/info/attributes file because when you're working in a bare repository you don't usually have a reference index, meaning that the contents of .gitattributes cannot be interrogated. e.g. In git diff branchA branchB - which branches .gitattributes should be used? BranchA, BranchB or even master? The reality is that when you have a working directory - then it just uses the .gitattributes in staged in the index. An argument could be made that you should any one of these branches attributes. In cases of the bare repository git and libgit2 use none of these and just rely on the .git/info/attributes.

Or maybe only the .gitattributes file of default branch should be copied and ignored other branches.

@lunny commented on GitHub (Mar 27, 2025): > In bare repositories if you want to adjust the gitattributes file you need to edit the .git/info/attributes file because when you're working in a bare repository you don't usually have a reference index, meaning that the contents of .gitattributes cannot be interrogated. e.g. In git diff branchA branchB - which branches .gitattributes should be used? BranchA, BranchB or even master? The reality is that when you have a working directory - then it just uses the .gitattributes in staged in the index. An argument could be made that you should any one of these branches attributes. In cases of the bare repository git and libgit2 use none of these and just rely on the .git/info/attributes. Or maybe only the `.gitattributes` file of default branch should be copied and ignored other branches.
Author
Owner

@wxiaoguang commented on GitHub (Mar 28, 2025):

There is also an upstream (git) proposal:

diff: add --attr-source to read gitattributes from a commit bc9c2b1463.1678758818.git.gitgitgadget@gmail.com/

@wxiaoguang commented on GitHub (Mar 28, 2025): There is also an upstream (git) proposal: diff: add --attr-source to read gitattributes from a commit https://patchwork.kernel.org/project/git/patch/bc9c2b1463a625ddab58cb72d4281f01d1f53bdb.1678758818.git.gitgitgadget@gmail.com/
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#14180