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?

Greg Bacon
  • 134,834
  • 32
  • 188
  • 245
trejder
  • 17,148
  • 27
  • 124
  • 216
  • Gerrit shouldn't display a different number. Can you link to the change on gerrit please? – Mureinik Apr 24 '15 at 13:35
  • 6
    `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. – Arkadiusz Drabczyk Apr 24 '15 at 14:05
  • IS this before or after submit? Was there an (invisible) rebase and/or merge occuring? – kdopen Apr 24 '15 at 16:54
  • @Mureinik Sorry, I can't. It is on company intranet. – trejder Apr 24 '15 at 18:54
  • @kdopen 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. – trejder Apr 24 '15 at 18:57
  • @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. – trejder Apr 24 '15 at 18:58
  • http://blogs.collab.net/teamforge/the-literally-hidden-risks-of-github-style-pull-requests-in-the-enterprise – Naveen Dennis Jul 16 '15 at 04:58
  • 1
    May be there may be is conversion from crlf to lf or vice versa that gerrit does not track or tabs vs spaces. – kazandzhiro Nov 25 '15 at 12:47

3 Answers3

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.

CM_
  • 11
  • 2
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.

atx
  • 4,831
  • 3
  • 26
  • 40
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)

A. Loiseau
  • 101
  • 1