Reputation: 325
I have many many files without extensions. I have one file called "model" and another file called "schema" which I know are both UTF-16. Both "model" and "schema" have no extension so are forced to binary when trying to git diff
. I want to convert "model" to UTF-8 and "schema" to JSON using .gitattributes so I can compare diffs.
Q1. How can I specify individual filenames without extensions to be correctly decoded?
Q2. I don't want to add bash scripts or change git --global settings so that its easier to use for others.
I could'nt find any example from the docs. I tried following this solution except only using *model diff=utf16
and git config file:
[diff "utf16"]
textconv = "iconv -f utf-16 -t utf-8"
but this didn't work. I've tried this in both VScode and on bash (Ubuntu20.04).
UPDATE:
@torek pointed me to helpful Git debugging tool. Here is my output from GIT_TRACE=1 git diff
09:58:09.927031 git.c:439 trace: built-in: git diff
09:58:09.951640 run-command.c:663 trace: run_command: unset GIT_PAGER_IN_USE; LESS=FRX LV=-c pager
Q1 SOLUTION
Both @torek and @jthill helped confirm the issue was on my end. The solution above should have worked but my local git config wasn't pointing to the .gitconfig
file. I updated the .git/config
file and it worked.
Q2 SOLUTION
You must edit global settings once for each repo to reference .gitconfig
. I've tried following this solution but can't seem to get it to revert to the .gitconfig file in the repo worktree root.
Upvotes: 1
Views: 884
Reputation: 60235
so are forced to binary
By what?
I do:
$ echo '/Makefile myattr=test' >.git/info/attributes
$ git ls-files ':(attr:myattr=test)'
Makefile
$ echo 'Makefile myattr=test' >.git/info/attributes
$ git ls-files ':(attr:myattr=test)' | wc -l
24
so there's 24 Makefiles and the anchored pattern matches only the specific one I want, because I anchored the path.
So put /model diff=utf16
in your .gitattributes
if that file's at the work tree root.
Upvotes: 2