git status

Short and porcelain status, branch headers, and untracked-file filtering, checked on Git 2.39.5.

命令页正文目前为英文。

git status summarizes the working tree and the index. The default long format is meant for humans and includes advice text that can change with configuration and Git version. For scripts, and for stable examples, use --porcelain=v1 or the short format -s.

Examples were checked on Git 2.39.5 in an isolated repository with no upstream, so the porcelain branch header is only ## main.

Examples were checked against Git 2.39.5. See the official documentation for the complete command.

Git command catalog → · Git tutorial overview →

Short and porcelain formats

Each porcelain v1 line starts with a two-letter XY code and a path. The first letter is the index state relative to HEAD; the second is the working tree state relative to the index. A leading space and M means an unstaged modification. MM means the file is staged and also has a later unstaged edit. ?? is untracked. A trailing space on the first column, as in "M " after git add, means a fully staged modification.

git status -s uses the same XY codes in this example. --porcelain=v1 -b adds a leading ## branch header. --untracked-files=no, also spelled -uno, hides untracked paths. The long human format is omitted here because it is verbose and includes help text.

git status --porcelain=v1, git status -s, git status -b, --untracked-files=no

git status [<options>] [--] [<pathspec>...]
git status -s
git status --porcelain=v1
git status --porcelain=v1 -b
git status --porcelain=v1 --untracked-files=no

Print a machine-stable view of staged, unstaged, and untracked paths.

ParameterDescription
--porcelain=v1The stable v1 porcelain format. Prefer this in scripts over the long format or a raw -s when you need a documented interface.
-b / --branchWith porcelain, print a ## line for the current branch before the path lines.
--untracked-files=noDo not list untracked files. -u no is the short form used as --untracked-files=no in the example.

Returns: Status lines on standard output. An empty porcelain list means a clean worktree and index, apart from ignored files.

  • A space in an XY code is significant. " M" and "M " are different states. Do not trim leading spaces.
bash
git init -b main >/dev/null
git config user.name "Practice Author"
git config user.email "[email protected]"
git config commit.gpgsign false
git config color.ui false
mkdir -p .disabled-hooks
git config core.hooksPath ".disabled-hooks"
printf 'v1\n' > tracked.txt
git add tracked.txt
git commit -m "Add tracked" >/dev/null
printf 'v2\n' > tracked.txt
printf 'new\n' > extra.txt
echo "short"
git status -s
echo "porcelain"
git status --porcelain=v1
echo "porcelain-b"
git status --porcelain=v1 -b
git add tracked.txt
printf 'v3\n' > tracked.txt
echo "mixed"
git status --porcelain=v1
echo "no-untracked"
git status --porcelain=v1 --untracked-files=no

Expected output

short
 M tracked.txt
?? extra.txt
porcelain
 M tracked.txt
?? extra.txt
porcelain-b
## main
 M tracked.txt
?? extra.txt
mixed
MM tracked.txt
?? extra.txt
no-untracked
MM tracked.txt

Related: git diff, git add

Official documentation →