60

Running a git commit leads to the following output:

[manu@host] git: git commit -a -m "StreamIt instrumentation"
[master 263410f] StreamIt instrumentation
62 files changed, 6117 insertions(+), 5748 deletions(-)
rewrite Code/ALCHEMY/streamit-src-2.1.1/src/at/dms/kjc/cluster/ClusterBackend.java (91%)
rewrite Code/ALCHEMY/streamit-src-2.1.1/src/at/dms/kjc/cluster/ClusterCodeGenerator.java (95%)
rewrite Code/ALCHEMY/streamit-src-2.1.1/src/at/dms/kjc/cluster/code/FlatIRToCluster.java (94%)
rewrite Code/ALCHEMY/streamit-src-2.1.1/src/at/dms/kjc/common/ToCCommon.java (92%)
rewrite Code/ALCHEMY/streamit-src-2.1.1/src/at/dms/kjc/flatgraph/ScheduledStaticStreamGraph.java (93%)
rename Code/ALCHEMY/streamit-src-2.1.1/src/at/dms/kjc/sir/lowering/fission/{StatelessDuplicate.java => HorizontalFission.java} (98%)
rewrite Code/ALCHEMY/streamit-src-2.1.1/src/at/dms/kjc/sir/lowering/partition/dynamicprog/DynamicProgPartitioner.java (93%)
  • What does git mean when it reports a file as 'rewrite'?
  • What is the meaning of the associated percentage?
  • Why is a percentage only associated with these lines among the 62 changed in this commit?
Mus
  • 7,290
  • 24
  • 86
  • 130
Manuel Selva
  • 18,554
  • 22
  • 89
  • 134

1 Answers1

65

Git uses heuristics to determine if a change was a renaming or copying of a file, and also if it is a "rewriting" of the file. Roughly speaking, if the diff between the old and new version is bigger than the new version itself, it's a "rewrite".

This is tuned for git's original use case of changing source files, most often making localised changes: since it is based on a line-by-line diff, things like reindenting a source file can trigger it. Also, since it is determined on-the-fly, diff options like "-b" and "-w" can change the evaluation of whether a change is a rewrite (or a copy, or a rename).

The percentage is git's "dissimilarity index" (as opposed to the percentage "similarity index" for a rename or copy). Probably something like the percentage of lines in the file that have changed.

araqnid
  • 127,052
  • 24
  • 157
  • 134
  • 2
    Ok thanks for this explanation. I performed Ctrl+Shift+F in Eclipse on this java files, i.e auto formating and as a consequence files have a lot of changes. Does git outputs display only rewrit and renamed files not the ones with "little changes" meaning that in my case all other changes among the 62 are minor ones ? – Manuel Selva Dec 01 '12 at 08:03
  • yes, that summary after commit lists files that are added, removed, renamed, copied or rewritten (it is the output of `git diff --summary HEAD^..`). So the other changes are "normal" changes to files- not enough to trigger the rewrite heuristic. – araqnid Dec 02 '12 at 12:05
  • 4
    OK, but what are the _implications_ of this? Does it modify the log display somehow? If `foo.txt` shows 65% rewrite, would the previous version of `foo.txt` not show up as the same file in the history, even though it hasn't been renamed? In other words, this is a heuristic for what purpose? And where is this explained in the official Git documentation? Your answer was really helpful for a start, but it left more questions unanswered … – Garret Wilson Apr 12 '20 at 17:00
  • I suppose it could just be feedback / warning @GarretWilson but I'd like someone knowledgeable to confirm that – NeilG Apr 15 '23 at 13:54