4

i want git status to also list number of lines changed, like those + and - on git pull:

example)

❯ LANG=c git status
On branch develop
Your branch is up to date with 'upstream/develop'.

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:   package-lock.json | 1093 ++++++++---
        modified:   package.json      | 26   +++---

since i could not find such options in docs, i then tried using diffstat, since it was used for git pull.

❯ git diff | diffstat -C
 package-lock.json | 1093 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
 package.json      |   26 +-
 2 files changed, 915 insertions(+), 204 deletions(-)

however there's two problems:

  1. diffstat results are entire terminal wide, so merging the result with git status result would break lines
  2. git diff cannot diff against untracked files

using lots of bash could fix 1, but i'm not sure how i could do 2 without modifying the index.

scarf
  • 303
  • 3
  • 9
  • 2
    Regarding point 1, `git diff` has a `--stat` argument that let's you avoid using an external program like `diffstat`, and it also accepts an optional width argument to limit the length of the lines, e.g. `git diff --stat=40 ...`. – hlovdal Aug 21 '22 at 11:20
  • `git status` simply does not do that, so you *will* need to write your own program (perhaps a shell script as you suggest). You'll next need to break down the problem into whatever steps you do understand how to do, and the ones you don't, and ask new questions about the ones you don't. – torek Aug 21 '22 at 17:15
  • (rewording a previous comment) : regarding 2., an untracked file could probably count as "all lines are added" ; displaying `$file | $(wc -l $file) ++++` with an appropriate number of "+" (I'll let you determine that part ...) should do the job – LeGEC Apr 17 '23 at 12:08

0 Answers0