Luke Davis
Luke Davis

Reputation: 2666

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

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.

Upvotes: 3

Views: 3425

Answers (2)

Sergey Zakharov
Sergey Zakharov

Reputation: 1603

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

Upvotes: 3

Schwern
Schwern

Reputation: 164819

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.

Upvotes: 6

Related Questions