d
Amit DhamuSoftware Engineer
 

Git Status Porcelain

2 minute read 00000 views

Given a simple git status command yields something like below, we can utilise some low-level options to simplify this list if we want to maybe pipe the files into a command.

git status
On branch master
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:   .gitignore
	modified:   index.js
	modified:   package.json
	modified:   yarn.lock

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	README.md

no changes added to commit (use "git add" and/or "git commit -a")

Porcelain

Porcelain commands are ones that Git describes as ones that are quite low-level and not ones that everyday users might need. However, for git status, this could be useful.

From the man git-status:

Give the output in an easy-to-parse format for scripts. This is similar to the short output, but will remain stable across Git versions and regardless of user configuration

Running it will give us something like below:

git status --porcelain
 M .gitignore
 M index.js
 M package.json
 M yarn.lock
?? README.md

We can take this further to remove the M or the ??:

git status --porcelain | sed s/^...//
.gitignore
index.js
package.json
yarn.lock
README.md

And if we wanted to put all of these onto one line to maybe pass to a script or pipe the output to another command, we could do something like:

git status --porcelain | sed s/^...//  | tr '\n' ' '
.gitignore index.js package.json yarn.lock README.md

To pass this to a script, we could do:

stat $(git status --porcelain | sed s/^...//  | tr '\n' ' ')