This is currently a bit tricky, and not working the way we want it to work in the long run.
First off: the .gitattributes
file MUST be encoded and tagged as iso8859-1. This is mentioned in the release notes PDF, but it’s probably easy to overlook.
Second: tags are set to match the attributes only on checkout. I’m not sure why git add
is setting the tags to iso8859-1; it shouldn’t be.
Third: attributes will only be honored once they are committed to the repo, so you want to commit the .gitattributes
file first.
Here’s a log of the steps I used to get to a good tree.
bash-2.03$ ls -alT
total 96
drwxr-xr-x 2 TSJLC PDUSER 8192 Nov 23 09:49 .
drwxr-xr-x 59 TSJLC PDUSER 28672 Nov 23 09:49 ..
- untagged T=off -rw-r--r-- 1 TSJLC PDUSER 13 Nov 23 09:49 Makefile
- untagged T=off -rw-r--r-- 1 TSJLC PDUSER 16 Nov 23 09:47 foo.c
- untagged T=off -rw-r--r-- 1 TSJLC PDUSER 16 Nov 23 09:47 foo.h
bash-2.03$ touch .gitattributes
bash-2.03$ chtag -tc819 .gitattributes
<Edit .gitattrbutes here>
bash-2.03$ head -9999 * .gitattributes
==> Makefile <==
# Some rules
==> foo.c <==
// Some .c file
==> foo.h <==
// Some .h file
==> .gitattributes <==
Makefile working-tree-encoding=ibm-1047 git-encoding=iso8859-1
*.c working-tree-encoding=ibm-1047 git-encoding=iso8859-1
*.cpp working-tree-encoding=ibm-1047 git-encoding=iso8859-1
*.h working-tree-encoding=ibm-1047 git-encoding=iso8859-1
*.hpp working-tree-encoding=ibm-1047 git-encoding=iso8859-1
*.md working-tree-encoding=ibm-1047 git-encoding=iso8859-1
bash-2.03$ git init .
Initialized empty Git repository in /u/tsjlc/gt/.git/
bash-2.03$ bash-2.03$ git add .gitattributes
bash-2.03$ git commit -m "commit .gitattributes before other files"
[master (root-commit) 4b0a252] commit .gitattributes before other files
1 file changed, 6 insertions(+)
create mode 100644 .gitattributes
bash-2.03$ ls -alT
total 120
drwxr-xr-x 3 TSJLC PDUSER 8192 Nov 23 09:53 .
drwxr-xr-x 59 TSJLC PDUSER 28672 Nov 23 09:52 ..
drwxr-xr-x 8 TSJLC PDUSER 8192 Nov 23 09:53 .git
t ISO8859-1 T=on -rw-r--r-- 1 TSJLC PDUSER 378 Nov 23 09:50 .gitattributes
- untagged T=off -rw-r--r-- 1 TSJLC PDUSER 13 Nov 23 09:49 Makefile
- untagged T=off -rw-r--r-- 1 TSJLC PDUSER 16 Nov 23 09:47 foo.c
- untagged T=off -rw-r--r-- 1 TSJLC PDUSER 16 Nov 23 09:47 foo.h
bash-2.03$ bash-2.03$ git add foo* Makefile
bash-2.03$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: Makefile
new file: foo.c
new file: foo.h
bash-2.03$ ls -alT
total 120
drwxr-xr-x 3 TSJLC PDUSER 8192 Nov 23 09:53 .
drwxr-xr-x 59 TSJLC PDUSER 28672 Nov 23 09:52 ..
drwxr-xr-x 8 TSJLC PDUSER 8192 Nov 23 09:55 .git
t ISO8859-1 T=on -rw-r--r-- 1 TSJLC PDUSER 378 Nov 23 09:50 .gitattributes
t ISO8859-1 T=on -rw-r--r-- 1 TSJLC PDUSER 13 Nov 23 09:49 Makefile
t ISO8859-1 T=on -rw-r--r-- 1 TSJLC PDUSER 16 Nov 23 09:47 foo.c
t ISO8859-1 T=on -rw-r--r-- 1 TSJLC PDUSER 16 Nov 23 09:47 foo.h
bash-2.03$ git commit -m "add the other source files"
git commit -m "add the other source files"
[master c5f24f6] add the other source files
3 files changed, 3 insertions(+)
create mode 100644 Makefile
create mode 100644 foo.c
create mode 100644 foo.h
bash-2.03$ bash-2.03$ rm Makefile foo*
bash-2.03$ git checkout -f --
bash-2.03$ ls -alT
ls -alT
total 120
drwxr-xr-x 3 TSJLC PDUSER 8192 Nov 23 10:00 .
drwxr-xr-x 59 TSJLC PDUSER 28672 Nov 23 09:52 ..
drwxr-xr-x 8 TSJLC PDUSER 8192 Nov 23 10:00 .git
t ISO8859-1 T=on -rw-r--r-- 1 TSJLC PDUSER 378 Nov 23 09:50 .gitattributes
t IBM-1047 T=on -rw-r--r-- 1 TSJLC PDUSER 13 Nov 23 10:00 Makefile
t IBM-1047 T=on -rw-r--r-- 1 TSJLC PDUSER 16 Nov 23 10:00 foo.c
t IBM-1047 T=on -rw-r--r-- 1 TSJLC PDUSER 16 Nov 23 10:00 foo.h
bash-2.03$ git check-attr -a *
Makefile: working-tree-encoding: ibm-1047
Makefile: git-encoding: iso8859-1
foo.c: working-tree-encoding: ibm-1047
foo.c: git-encoding: iso8859-1
foo.h: working-tree-encoding: ibm-1047
foo.h: git-encoding: iso8859-1
bash-2.03$
I know - that “rm” step is ugly. Another way to do this would be to do the first two commits (for the .gitattributes
file and the source), then copy the .git
directory to a new directory and do a git checkout
to check out the source (and have it correctly tagged).
Note that, once you have the repo up and running, you will rarely have to fiddle with the attributes; it all just works.
Thanks for testing this, and I hope this helps.
– Jerry