日本語

Reading the Symbols in git status –short

​​Git​command line

git status --short (or git status -s for short) lists each changed file on its own line, with a two-character code at the start that shows its state. The left character is the state in the index (staging area), and the right character is the state in the working tree. This reading helps when you want to see quickly which files are staged and which are not before you commit. I checked the output before and after each change in a test environment, where I added, modified, and deleted files.

Note

The test environment was Ubuntu 24.04 with Git 2.43.0. I set placeholder values (Neko <neko@example.com>) for the author name and email. For the remote, I used a bare repository (../remote.git) created in the same environment. I did not test colored output, submodule markers, or behavior on Windows and macOS.

The left column is the index, the right column is the working tree

The official git status reference describes each line in short format as XY PATH. X is the state in the index, and Y is the state in the working tree. A side that has not changed is shown as a space.

The characters that appear are:

Character Meaning
(space) Not changed
M Modified
A Added
D Deleted
R Renamed
T File type changed (for example, a regular file replaced by a symbolic link)
C Copied (when the status.renames setting is copies)
U Unmerged (conflicted during a merge)
?? Untracked by Git
!! Ignored (when --ignored is given)

When nothing has changed, git status --short prints nothing. It does not print the long-form message "nothing to commit, working tree clean."

console
$ git status --short

$ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

A new file goes from ?? to A

A file you just created is not tracked by Git yet, so it shows ??. After git add, the left column shows A and the right column is a space. This means the file is added to the index, and the index and working tree now match.

console
$ printf "カート\n" > cart.txt

$ git status --short
?? cart.txt

$ git add cart.txt

$ git status --short
A  cart.txt

For a modified file, the column tells you whether it is staged

When I added a line to login.txt, which was already committed, M appeared in the right column. The line starts with a space, so it looks like M shifted by one character. The file has changed in the working tree but is not staged yet.

console
$ printf "パスワード欄\n" >> login.txt

$ git status --short
A  cart.txt
 M login.txt

After I ran git add login.txt, the M moved to the left column. The change is now in the index, and the index and working tree match.

console
$ git add login.txt

$ git status --short
A  cart.txt
M  login.txt

When I changed the same file again after staging it, both columns showed M, giving MM. The index holds only the first change, and the working tree still has the later change.

console
$ printf "ログアウト\n" >> login.txt

$ git status --short
A  cart.txt
MM login.txt

When I changed a file after staging it as a new file, the code became AM.

console
$ printf "カートの合計\n" >> cart.txt

$ git status --short
AM cart.txt
MM login.txt

In the long form, the same file appears under both "Changes to be committed" (staged) and "Changes not staged for commit." In short form, the left column corresponds to the first heading and the right column to the second.

console
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   cart.txt
	modified:   login.txt

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   cart.txt
	modified:   login.txt

Deletions and renames

For deletions, the meaning also depends on which column the D appears in. If you delete a file with rm, D appears in the right column as D. If you delete it with git rm, the deletion goes into the index, so D appears in the left column.

console
$ rm memo.txt

$ git status --short
AM cart.txt
MM login.txt
 D memo.txt

$ git rm -q config.txt

$ git status --short
AM cart.txt
D  config.txt
MM login.txt
 D memo.txt

When I renamed a file with git mv, the R line showed the old and new names joined by ->.

console
$ git mv README.md README.txt

$ git status --short
R  README.md -> README.txt
AM cart.txt
D  config.txt
MM login.txt
 D memo.txt

An untracked folder shows only its name

By default, a folder that contains only untracked files shows as a single line with the folder name. To see each file inside, add -uall (--untracked-files=all). See the official reference for –untracked-files.

console
$ mkdir -p docs/img && printf "a\n" > docs/a.md && printf "b\n" > docs/img/b.md

$ git status --short
R  README.md -> README.txt
AM cart.txt
D  config.txt
MM login.txt
 D memo.txt
?? docs/

$ git status --short -uall
R  README.md -> README.txt
AM cart.txt
D  config.txt
MM login.txt
 D memo.txt
?? docs/a.md
?? docs/img/b.md

Ignored files show up with !!

The .gitignore in this repository includes *.log. When I created debug.log, it did not appear in git status --short. With --ignored, the ignored file was shown with !!.

console
$ printf "ログ\n" > debug.log

$ git status --short
R  README.md -> README.txt
AM cart.txt
D  config.txt
MM login.txt
 D memo.txt
?? docs/

$ git status --short --ignored
R  README.md -> README.txt
AM cart.txt
D  config.txt
MM login.txt
 D memo.txt
?? docs/
!! debug.log

Adding -b shows the branch and its difference from the remote on the first line

By default, the short form does not show the branch name. With --branch (-b), the first line shows ## branch...upstream. After I committed the changes so far and tried it, [ahead 1] showed that the local branch was one commit ahead of the remote. -s and -b can be combined as -sb.

console
$ git add -A && git commit -q -m "いろいろ変更"

$ git status --short --branch
## main...origin/main [ahead 1]

$ git status -sb
## main...origin/main [ahead 1]

After I pushed, the bracketed part disappeared.

console
$ git push -q

$ git status -sb
## main...origin/main

A conflicted file shows UU

While a merge has conflicts, the two characters have different meanings. According to the official reference, X and Y describe how each side of the merge changed the file. I changed the same line of the same file on both the feature branch and the main branch, then merged. The output showed UU. The final git merge --abort returned the repository to the state before the merge.

console
$ git switch -q -c feature

$ printf "# 猫の手アプリ(feature)\n" > README.txt && git commit -q -am "featureでREADMEを変更"

$ git switch -q main

$ printf "# 猫の手アプリ(main)\n" > README.txt && git commit -q -am "mainでREADMEを変更"

$ git merge feature
Auto-merging README.txt
CONFLICT (content): Merge conflict in README.txt
Automatic merge failed; fix conflicts and then commit the result.

$ git status --short
UU README.txt

$ git merge --abort

The official reference lists seven conflict combinations. In the table, "our side" and "their side" correspond to us and them in the official reference.

Code Meaning
UU Modified on both sides
AA Added on both sides
DD Deleted on both sides
AU Added on our side
UA Added on their side
DU Deleted on our side
UD Deleted on their side

When a Japanese file name shows up as "02…"

By default, a file with a Japanese name appears in double quotes, with its bytes written as octal values. Setting core.quotePath to false shows the name as it is (official reference for core.quotePath).

console
$ echo 買い物 > 買い物メモ.txt

$ git status --short
?? "\350\262\267\343\201\204\347\211\251\343\203\241\343\203\242.txt"

$ git -c core.quotePath=false status --short
?? 買い物メモ.txt

Here, -c changes the setting for that one command only. If you set it with git config --global core.quotePath false, the name is shown as it is without -c.

console
$ git config --global core.quotePath false

$ git status --short
?? 買い物メモ.txt

To undo the setting, run git config --global --unset core.quotePath.

Running from a subfolder counts paths from the current directory

The paths in git status --short are shown relative to the folder you are in. I created order.txt, added a line to login.txt, and then ran the command from the subfolder sub. The files at the top of the repository were shown with ../.

console
$ printf "注文\n" > order.txt && printf "ログイン2\n" >> login.txt

$ mkdir sub

$ cd sub

$ git status --short
 M ../login.txt
?? ../order.txt

$ git status --porcelain
 M login.txt
?? order.txt

--porcelain is a format meant for scripts. The status codes are the same as with --short, but paths are always counted from the top of the repository, and the color setting does not affect the output. Git also guarantees that this format will not change in an incompatible way between versions (official reference on the porcelain format). Use --short when a person is reading the output, and --porcelain when a shell script checks the first two characters of each line to decide what to do.

​Posted by 86