I've moved a file manually and then I've modified it. According to Git, it is a new file and a removed file. Is there any way to force Git into treating it as a file move?
Question
Answer
Git will automatically detect the move/rename if your modification is not too severe. Just git add
the new file, and git rm
the old file. git status
will then show whether it has detected the rename.
additionally, for moves around directories, you may need to:
- cd to the top of that directory structure.
- Run
git add -A .
- Run
git status
to verify that the "new file" is now a "renamed" file
If git status still shows "new file" and not "renamed" you need to follow Hank Gay’s advice and do the move and modify in two separate commits.