Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see the number of lines changed/deleted/added for unstaged/staged files with `git status`?

Tags:

git

When I run git status, I can see that certain files have been modified, but that get no more information. Is there any way to see the total number of lines changed/deleted/added in these files, even if they are unstaged/uncommitted?

This would be helpful because I sometimes make major changes to one file, then really minor changes to other files spontaneously. I would like to commit these groups separately, and with separate commit messages, for organization. And having this capability with git status would help me determine at-a-glance which files have had only very minor changes.

like image 464
Luke Davis Avatar asked Oct 15 '25 15:10

Luke Davis


2 Answers

Is there any way to see the total number of lines changed/deleted/added in these files, even if they are unstaged/uncommitted?

Yes, git diff --stat. Though this won't show untracked files.

git diff shows the difference between the working copy and the staging area. --stat, and various other flags, format it.

This would be helpful because I sometimes make major changes to one file, then really minor changes to other files spontaneously. I would like to commit these groups separately, and with separate commit messages, for organization.

Two additional commands are handy here.

git commit -v will show you the full diff in your editor while you're writing the commit message. Useful for a quick review.

git add -p will allow you to decide which hunks to add to the staging area.

like image 92
Schwern Avatar answered Oct 18 '25 07:10

Schwern


For staged files you can do this with git diff --staged --stat or git diff --cached --numstat.

like image 38
Sergey Zakharov Avatar answered Oct 18 '25 06:10

Sergey Zakharov