tnull
tnull

Reputation: 758

How to tell git I didn't move a file?

I consolidated java-files with mostly duplicate functionality. Therefore I copied code from one class to another and then deleted the old (now unnecessary) file. When I want to commit this consolidation, git recognizes this as file renaming (probably because of the mostly overlapping code), even though it wasn't.

Is there a way to tell git that this file shouldn't be seen as renamed, but as one update and one deletion?

Upvotes: 1

Views: 66

Answers (1)

musiKk
musiKk

Reputation: 15189

No. A move/rename is not handled separately from all other updates. It's just a matter of how it's displayed. Git uses a similarity index to determine when it should consider something a rename. By default this is 50%, meaning, if you have a remove and an add and at least 50% of the involved lines are shared, this is considered a rename.

You can try different values with the -M option of git-log:

-M[<n>]

--find-renames[=<n>]

If generating diffs, detect and report renames for each commit. For following files across renames while traversing history, see --follow. 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%. The default similarity index is 50%.

Upvotes: 2

Related Questions