Display renamed files in GitWeb

96 Views Asked by At

I rename some files with git mv. Normally git status would detect this and display that these files were renamed. However in GitWeb these files are displayed as deleted and created with new name. Is there a way to tell GitWeb to try to detect renamed files? Maybe, some other web-based Git viewer can do this?

1

There are 1 best solutions below

1
On BEST ANSWER

Git doesn't track renames. It actually treats the following two operations in exactly the same way:

  1. Rename a file within Git:
    • git mv foo bar
  2. Delete a file and then add a new one with the same content:
    • cp foo bar
    • git rm foo
    • git add bar

Some tools will display something along the lines of "foo renamed to bar", but it's just a guess based on similar content. Other tools will display "deleted foo and added bar". To Git they're the same thing.

The gitweb.conf manpage lists a configuration directive that can be used to change how renames are detected:

@diff_opts

Rename detection options for git-diff and git-diff-tree. The default is ('-M'); set it to ('-C') or ('-C', '-C') to also detect copies, or set it to () i.e. empty list if you don’t want to have renames detection.

Note that rename and especially copy detection can be quite CPU-intensive. Note also that non git tools can have problems with patches generated with options mentioned above, especially when they involve file copies ('-C') or criss-cross renames ('-B').

It looks like the default value of ('-M') is what you want (from the git-diff manpage):

-M[<n>]
--find-renames[=<n>]

Detect renames. If n is specified, it is a threshold on the similarity index (i.e. amount of addition/deletions compared to the file’s size). For example, -M90% means git should consider a delete/add pair to be a rename if more than 90% of the file hasn’t changed. Without a % sign, the number is to be read as a fraction, with a decimal point before it. I.e., -M5 becomes 0.5, and is thus the same as -M50%. Similarly, -M05 is the same as -M5%. To limit detection to exact renames, use -M100%.

Perhaps the files you're comparing also have enough different content that they are not being detected as a rename?