Git¶
Configuration¶
Global¶
Tips & tricks¶
Identify distinct file extensions¶
The following command pipeline prints all distinct file extensions, or filenames if the filename has no extension:
find -- . -type d -name .git -prune -o \! -type d -print0 \
| gawk -v RS='\0' -v ORS='\0' -- '{ match($0, /\/([^\/]+)$/, a); s = a[1]; print match(s, /(\.[^.]+)$/, a) ? a[1] : s }' \
| sort -fuz \
| gawk -v RS='\0' -v ORS='\n' -- '{ print gensub(/[^[:print:]]+/, "�", "g") }'
This helps with creating gitignore and gitattributes files.
Debug gitignore patterns¶
The following command pipeline prints a four-column table that may be useful for debugging gitignore patterns:
find -- . -type d -name .git -prune -o \! -type d -print0 \
| sort -fz \
| git check-ignore -nvz --no-index --stdin \
| gawk -v RS='\0' -v ORS='\n' -- '{ print gensub(/[^[:print:]]+/, "�", "g") }' \
| paste -s -d '\t\t\t\n' -- - \
| awk -v FS='\t' -v OFS='\t' -- '{ print $4, $1, $2, $3 }' \
| column -t -s $'\t'
The four columns:
- path of a file being queried
- pattern's source file
- line number of the pattern within that source
- matching pattern
If some file does not match a gitignore pattern, then all columns except (1) will be empty.
Debug text
and eol
attributes¶
The following command pipeline prints a four-column table that may be helpful for debugging the
text
and eol
attributes. Among other things, it prints the file content identification used by
Git when the text
attribute is auto
(or not set and the core.autocrlf
config option is not
false).
read -r -d '' GAWK_PROG << 'EOF' || true
BEGIN {
RS = "\0"
OFS = "\t"
ORS = "\n"
}
{
match($0, /^([^ ]+) +([^ ]+) +([^\t]+)\t(.+)$/, a)
a[3] = gensub(/ +$/, "", "g", a[3])
a[4] = gensub(/[^[:print:]]+/, "�", "g", a[4])
print a[1], a[2], a[3], a[4]
}
EOF
git ls-files -coz --eol --exclude-standard \
| gawk -- "${GAWK_PROG}" \
| sort -f -t $'\t' -k 1,1 -k 2,2 -k 3,3 -k 4,4 \
| column -t -s $'\t'
The four columns:
-
eolinfo
of the contents in the index for the path. Possible values: -
eolinfo
of the contents in the worktree for the path. Possible values: -
eolattr
that applies to the path. Possible values:eolattr/ eolattr/-text eolattr/text eolattr/text eol=crlf eolattr/text eol=lf eolattr/text=auto eolattr/text=auto eol=crlf eolattr/text=auto eol=lf
-
path
Renormalize repository¶
After modifying a gitattributes file, run the following from a clean working directory: