You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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.
Activity
wxiaoguang commentedon Mar 27, 2025
wxiaoguang commentedon Mar 27, 2025
Shuenhoy commentedon Mar 27, 2025
wxiaoguang commentedon Mar 27, 2025
wxiaoguang commentedon 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.[-].gitittributes cannot exclude file from diff after 1.23[/-][+]"git diff" doesn't respect gitattributes file on a bare repo[/+]wxiaoguang commentedon 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
Shuenhoy commentedon 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.wxiaoguang commentedon Mar 27, 2025
I think it is feasible, if some people would like to implement it.
lunny commentedon Mar 27, 2025
Or maybe only the
.gitattributes
file of default branch should be copied and ignored other branches.wxiaoguang commentedon 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/