Fixing a missing git rename, after manual mv + edit
I happily reorganized some Frameworks, trusting that
git add --all would pick up the changes. It did for the most of the files. But I edited some files to fix them, and apparently - judging from the output of
git commit --dry-run -a and
git status - it wouldn’t have picked up some renames.
That’s something I don’t like, because it means losing the history for that file, unless I remember that an orphan exists somewhere in the git tree.
I didn’t commit anything yet. But I did run
git add -all. A good idea may have been to run
git add -all --dry-runbeforehand.
Here’s how I fixed that:
git add -u new/file.m # undo add of new file git reset -- old/file.m # undelete old file in staging mv new/file.m old/file.m # mv new file in place of old git mv -f old/file.m new/file.m # let git move it back
Now it shows up in
git status like this, which should be OK.
deleted: new/file.m renamed: old/file.m -> new/file.m modified: new/file.m