1

I've learned I can use count to find the NUMBER of commits a branch is ahead/behind by, like so:

git rev-list --count HEAD..@{u}

But is there a way to do so for uncommitted files?

Just found out git status -suno shows how many files have been changed in a really concise way, so I could either count the lines of the output (with echo "$var" | wc -l) or just put a symbol to denote an arbitrary amount exist, or parse it in a weird way to see the number of deleted/added/modified.

However, do non "porcelain" and more directly-addressing commands exist to accomplish this task, as parsing commands such as these are seen as bad practice?

Also, I am using this to add to a git-bash prompt; I would normally just type in git status, but would like to have maximum convenience by just showing such.

1 Answers1

1

Ironically, the --porcelain option of git status is meant to be parsed:

 git status --porcelain -suno|wc -l

So while git status is porcelain, git status --porcelain does produce output suitable for consumption by porcelain scripts.

I tried to explain said option in "What does the term “porcelain” mean in Git?"

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Interesting (and also kind of annoying)! However, using `git status --porcelain` gives me an output of `?? newFile.txt` as expected, as I only ran `touch newFile.txt` before hand, but adding the `-suno` flag changes the output to nothing. I have already written some code to parse `git status -suno`; can I expect porcelain to produce a similar output (displaying two letters, one denoting the working tree, and one denoting the index)? – Barrett Ruth Jun 28 '20 at 01:40
  • @ByNoMeans It will count modified files, meaning their content has been modified. A simple touch would not count in that mode. – VonC Jun 28 '20 at 02:00