6

I did some refactoring and git rm on old file and git add on new files. It is showing up as a rename from old file to one of my new files:

renamed:    src/P/Foo/PicturePosition.php -> src/P/Model/Block/Drawing/OffsettedPosition.php

even though I never did any git mv and the files have different content. Why is this happening to me? Should I even try to fix it, and if yes, how?

I use git 1.9.1

Jesvin Jose
  • 22,498
  • 32
  • 109
  • 202
  • 1
    Is the content of the two files identical? – yan Jun 11 '14 at 12:48
  • 4
    Basically, git looks at the content of any particular file, and if a certain threshold percentage of lines are the same as some file it previously indexed (and the old file doesn't exist any more), it assumes that that file is the same file simply moved to a different location/filename, and is thus a ``rename``. It's not a bug, it's a feature ;) – aruisdante Jun 11 '14 at 12:48
  • possible duplicate of [How can I prevent git from thinking I did a rename](http://stackoverflow.com/questions/15031576/how-can-i-prevent-git-from-thinking-i-did-a-rename) – aruisdante Jun 11 '14 at 12:57

1 Answers1

4

Git doesn't record renames. It stores just the source trees and infers from the diffs which files were added, deleted, copied, renamed and/or edited.

git mv is just syntactic sugar for a git rm, mv, then git add, and is probably there to make Subversion users feel happier. There is no need to use git mv to inform git that you have renamed a file.

My typical workflow is to just manipulate the files from my shell and editor, then do a git add -Av to tell git to figure out for itself what changes I just made. I don't think I've ever used git mv.

pndc
  • 3,710
  • 2
  • 23
  • 34
  • 1
    With info that git looks up content of the files and generates a **similarity index** for files, and uses that to determine if an operation was a rename https://stackoverflow.com/questions/15031576/how-can-i-prevent-git-from-thinking-i-did-a-rename – Jesvin Jose Jun 12 '14 at 06:16
  • 1
    This should be `git rm --cached` to unstage and remove the path only from the index. Without this flag, the file will be removed from the working tree and there will be no subsequent file to rename. – Leo Apr 01 '20 at 10:43