Why does Gerrit show a different number of changes than git does?
Asked Answered
R

3

14

This is the result of my latest commit / change in Git...

enter image description here

...and in Gerrit:

enter image description here

Is there any explanation for difference in number of lines added and deleted? Different algorithm?

Reclusion answered 24/4, 2015 at 13:32 Comment(8)
Gerrit shouldn't display a different number. Can you link to the change on gerrit please?Kovacs
Gerrit uses jgit. There is a jgit binary available. Try running jgit show on your commit and check if diffs produced by jgit and git are different. I remember I encountered a similar situation.Educatee
IS this before or after submit? Was there an (invisible) rebase and/or merge occuring?Bainbridge
@Kovacs Sorry, I can't. It is on company intranet.Reclusion
@Bainbridge After submit and push. There was not rebase, merge or anything, that I know. Just as usually: git status + git add -A + git commit -m "" + git push. I don't know, if this is the only situation, that I found by pure accident or if differences are after every commit / push. I don't have access to company intranet for next three days, so I can't verify this further.Reclusion
@ArkadiuszDrabczyk I'm a Windows geek! :> I don't know, if I manage to bring jgit to my Git for Windows environment. Will try on Monday.Reclusion
blogs.collab.net/teamforge/…Stumble
May be there may be is conversion from crlf to lf or vice versa that gerrit does not track or tabs vs spaces.Traynor
O
1

The actual changes are same. But the difference is due to how GIT and GERRIT computes the number of lines changed. Say you have 4 versions/changes/patchsets of the commit on top of HEAD.

commit_patchset#4
commit_patchset#3
commit_patchset#2
commit_patchset#1
HEAD

Git:
Number of lines changed for commit#4(A1): diff between commit_patchset#4 and commit_patch#3
Number of lines changed for commit#3(B1): diff between commit_patchset#3 and commit_patch#2
Number of lines changed for commit#2(C1): diff between commit_patchset#2 and commit_patch#1
Number of lines changed for commit#1(D1): diff between commit_patchset#1 and HEAD

Gerrit:
Number of lines changed for commit#4(A2): diff between commit_patchset#4 and BASE/HEAD
Number of lines changed for commit#3(B2): diff between commit_patchset#3 and BASE/HEAD
Number of lines changed for commit#2(C2): diff between commit_patchset#2 and BASE/HEAD
Number of lines changed for commit#1(D2): diff between commit_patchset#1 and BASE/HEAD

So always the number of lines changed will be different.

You can ask Gerrit to show the exact difference (as GIT shows) between patchset version instead of BASE/HEAD using ".." option.
For example,
http://your_gerrit_url/your_change_id/4..3 gives you the exact lines changed between commit_patchset#4 and commit_patchset#3. This should match the GIT calculations.

Hope it helps.

Obscurant answered 6/7, 2017 at 8:9 Comment(0)
B
0

If you have pushed multiple times then it's because your reference version is against something other than the base commit in the change.

Blinding answered 11/12, 2015 at 14:56 Comment(0)
D
0

Each git commits points to an entire git tree snapshot (which makes checkouting or diffing any revision very fast and quite constant time). Git does not store patches internally, they are computed on-demand when required like when commit stats are computed.

git diff is the main command to compute them, and it handles several diff algorithms (see --diff-algorithm at least). Also git configuration can set specific default diff behaviors (see diff.dirstat and diff.algorithm configs).

If both tools/machines computes diff stats with different diff settings then you might get different stats at the end. (I don't know if this is the case)

Direction answered 12/6, 2016 at 19:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.