12

I'm merging two branches in git, having a week worth of work each and some of the files were moved or renamed and modified.

Git seems to get the stuff completely wrong in some cases and it says file a was moved to file b when in reality they are totally unrelated.

I'm having quite a few such false positives (roughly 25%). I would like to influence the algorithm Git uses to figure out whether a file was moved, renamed or is new.

  • I'd like to assign higher priority to names. (file a was moved from folder foo to folder b) yet git insists that it was renamed to be file b in folder foo - totally unrelated)
  • I'd like to bump up the similarity index above which Git considers a file to be rename/move

I know I read somewhere I can do the latter and I hope I can do the former too, but my googling skills are failing me today.

Krzysztof Kozmic
  • 27,267
  • 12
  • 73
  • 115
  • 2
    Be aware that even if you find a way to alter the heuristics, it will only apply to your local machine. Just as the `git mv` command is a shorthand for `git rm` and `git add`, no metadata is persisted about a rename. – Troels Thomsen Apr 14 '11 at 10:01
  • aye. That's more than fine. Right now when I do diff it looks like crap and I can't tell what's really changed. And that's my goal here - be able to reliably see what has *really* changed and adjust if needed. – Krzysztof Kozmic Apr 14 '11 at 10:09

1 Answers1

6

I've noticed this too. I think "--find-renames=90" will be stricter than the default.

From the git diff documentation http://git-scm.com/docs/git-diff

-M[n] --find-renames[=n] Detect renames. If n is specified, it is a 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.

-C[n] --find-copies[=n] Detect copies as well as renames. See also --find-copies-harder. If n is specified, it has the same meaning as for -Mn.

Kent
  • 464
  • 4
  • 5
  • Looks like documentation moved from kernel.org, is there another place to look it up? – Roman May 08 '12 at 17:24
  • This is throwing an error for me. Can you be a little more specific about the syntax please? git --find-renames=100 Unknown option: --find-renames=100 – fIwJlxSzApHEZIl Nov 12 '14 at 00:59