Search code examples
gitgit-mv

How do you tell git that a delete and and add are really a move?


Most of the time, git can figure out when I've moved a file, but sometimes it can't. Is there a way to tell git, "trust me, this is a move?"

A key component of this is that I am using a tool to rename the file. It would be annoying to have to revert the rename and try again as a git mv, especially if other changes happened to the file before/after the move.


Solution

  • If you find a file is being added and deleted, but is really a move, it'll be detected as a move when adding both halves

    However, if other changes were made to the file, it's not a move, but a normal changeset - if you want to represent the move, separate that out into another commit, perhaps by stashing the other changes away