Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git-diff: Only show changes staged for committing

Tags:

git

git-diff

I want to see diff on files that I've added to commit (git add something). I can do this:

git diff HEAD `git status -s | grep ^M | cut -c 4-` 

Is there a shorter way?

like image 429
Alexey Avatar asked Apr 26 '12 08:04

Alexey


People also ask

How do you see which files are staged for commit git?

simply typing git status gives you a list of staged files, a list of modified yet unstaged files, and a list of untracked files. @houtanb, git status shows you a diff. (It doesn't show you all staged files).

Which command lists the difference between the staged changes and the previous commit?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit.


1 Answers

You can use git diff --staged (or git diff --cached) to see the diff that will be used when committing.

From the manpage:

git diff [--options] --cached [<commit>] [--] [<path>...]
This form is to view the changes you staged for the next commit relative to the named <commit>. Typically you would want comparison with the latest commit, so if you do not give <commit>, it defaults to HEAD. If HEAD does not exist (e.g. unborned branches) and <commit> is not given, it shows all staged changes. --staged is a synonym of --cached.

like image 179
ThiefMaster Avatar answered Sep 17 '22 19:09

ThiefMaster