Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git diff --stat explanation

Tags:

git

diff

diffstat

Git's pull output has been explained here fairly well. In spite of this I'm still unsure exactly what the text graph relates to.

For example:

git diff --stat master HEAD^

Outputs (truncated):

Site/index.php | 118 ++--

While the number of lines modified is clearly displayed as 118, the text graph is a little harder to interpret.

Could this relate to the ratio of added and removed lines?

like image 970
LukasWildas Avatar asked Aug 11 '11 11:08

LukasWildas


People also ask

What does git diff show you?

The git diff command displays the differences between files in two commits or between a commit and your current repository. You can see what text has been added to, removed from, and changed in a file. By default, the git diff command displays any uncommitted changes to your repository.

How does git calculate diff?

Computing diffsThe diff is dynamically generated from the snapshot data by comparing the root trees of the commit and its parent. Git can compare any two snapshots in time, not just adjacent commits. To compare two commits, start by looking at their root trees, which are almost always different.

What does ++ mean in git diff?

When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.

What is the difference between the git diff and git status?

The main difference between the commands is that git diff is specially aimed at comparisons, and it's very powerful at that: It can compare commits, branches, a single file across revisions or branches, etc. On the other hand, git status is specifically for the status of the working tree.


2 Answers

Yes it's the ratio of added and removed lines.

See also:

man diffstat
like image 177
Patrick B. Avatar answered Oct 19 '22 16:10

Patrick B.


git diff --numstat "@{1 day ago}"

Parameters:

  • diff = Show diff
  • --numstat = show the number of lines inserted and removed
  • @{1 day ago} = Period.

Output

0   1   WebContent/WEB-INF/tags/Grid.tag
38  30  ant/build.xml
  • Column 1 (containing 0 38) = inserted
  • Column 2 (containing 1 30) = removed

PS: Columns are separated by tab (\t).

like image 29
Edgard Leal Avatar answered Oct 19 '22 15:10

Edgard Leal