Skip to content
shellhacks.dev
Command Line

List Tracked Files in a Git Repository with ls-files

List tracked files with git ls-files. A name with non-ASCII bytes is printed quoted with octal escapes unless core.quotePath is off or -z is used.

1 min read
Summarize in AI

You want the list of files Git tracks, and the one with an accented name comes out as something unreadable.

Shell
git init -q repo && cd repo
echo a > a.txt
echo b > 'é.txt'
git add .
git ls-files
echo ---
git -c core.quotePath=off ls-files
echo ---
git ls-files -z | tr '\0' '\n'
Text
a.txt
"\303\251.txt"
---
a.txt
é.txt
---
a.txt
é.txt

git ls-files prints the paths in the index, relative to the current directory. By default Git quotes any name that has bytes above 127 in C style, giving octal escapes, to keep one path on one line, as the core.quotePath entry in the git config manual explains. Turning it off prints the real name, and -z ends each path with a NUL byte instead, which is the only fully safe form for scripts.

The list covers the index, so a file you deleted but did not stage still shows, and untracked files never appear; add -o --exclude-standard for those. Run from a subdirectory the command lists only that subtree. git ls-tree -r HEAD --name-only lists what is committed.

Taggedgit
Share

More snippets

Command Line

Avoid Parsing ls Output in Shell Scripts

Do not loop over the output of ls in a script. File names with spaces or a newline split into pieces, while a glob such as ./* hands over each name whole.

1 min read

Get new posts by email

One email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.