Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell Git it got moves/renames wrong (false positives)

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.

like image 250
Krzysztof Kozmic Avatar asked Apr 14 '11 09:04

Krzysztof Kozmic


People also ask

Does git detect moved files?

In Git's case, it will try to auto-detect renames or moves on git add or git commit ; if a file is deleted and a new file is created, and those files have a majority of lines in common, Git will automatically detect that the file was moved and git mv isn't necessary.

What does git rename do?

We use the git mv command in git to rename and move files. We only use the command for convenience. It does not rename or move the actual file, but rather deletes the existing file and creates a new file with a new name or in another folder.

Can you rename a file in git?

In your repository, browse to the file you want to rename. In the upper right corner of the file view, click to open the file editor. In the filename field, change the name of the file to the new filename you want. You can also update the contents of your file at the same time.


1 Answers

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.

like image 98
Kent Avatar answered Oct 05 '22 23:10

Kent