Skip to content

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

Open
@Shuenhoy

Description

@Shuenhoy

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

Activity

wxiaoguang

wxiaoguang commented on Mar 27, 2025

@wxiaoguang
added
issue/needs-feedbackFor bugs, we need more details. For features, the feature must be described in more detail
on Mar 27, 2025
wxiaoguang

wxiaoguang commented on Mar 27, 2025

@wxiaoguang
Shuenhoy

Shuenhoy commented on Mar 27, 2025

@Shuenhoy
Author
wxiaoguang

wxiaoguang commented on Mar 27, 2025

@wxiaoguang
wxiaoguang

wxiaoguang commented on Mar 27, 2025

@wxiaoguang
Contributor

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.

changed the title [-].gitittributes cannot exclude file from diff after 1.23[/-] [+]"git diff" doesn't respect gitattributes file on a bare repo[/+] on Mar 27, 2025
wxiaoguang

wxiaoguang commented on Mar 27, 2025

@wxiaoguang
Contributor

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

added and removed
issue/needs-feedbackFor bugs, we need more details. For features, the feature must be described in more detail
on Mar 27, 2025
Shuenhoy

Shuenhoy commented on Mar 27, 2025

@Shuenhoy
Author

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.

wxiaoguang

wxiaoguang commented on Mar 27, 2025

@wxiaoguang
Contributor

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.

lunny

lunny commented on Mar 27, 2025

@lunny
Member

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.

added
type/proposalThe new feature has not been accepted yet but needs to be discussed first.
on Mar 27, 2025
wxiaoguang

wxiaoguang commented on Mar 28, 2025

@wxiaoguang
Contributor

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/

added
type/upstreamThis is an issue in one of Gitea's dependencies and should be reported there
on Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue/workaroundit is or has a workaroundtype/proposalThe new feature has not been accepted yet but needs to be discussed first.type/upstreamThis is an issue in one of Gitea's dependencies and should be reported there

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @lunny@wxiaoguang@Shuenhoy

        Issue actions

          "git diff" doesn't respect gitattributes file on a bare repo · Issue #33703 · go-gitea/gitea