Git file renaming issues (deleting/adding instead of renaming)

— 2 minute read

Boost on DEV

Photo by Markus Spiske on Unsplash

Hey folks, I need a little help as I've kind of reached the extend of my gitfu.

I'm [working on a PR]( issuecomment-460886960) and I didn't realise at the time, but some files were committed as a deleted file (the original file) and a new file (the rename of the old file) when I renamed some of them. I was asked to ensure it's renamed in Git so as to preserve the history. Fair enough.

So if you look at the comments in the PR (I link to the first one about renaming in there), you'll see that I've done the following in a few different was but here is the gist of it:

  • Recovered the deleted file, source/libs/icons.js

  • Deleted the new file, source/libs/icons.tsx

  • Commit those changes

  • Run a git mv source/libs/icons.js source/libs/icons.tsx

  • Push to the remote, and the PR shows it as a file rename with no file changes.

  • The next commit is putting back the changes I had in source/libs/icons.tsx .

  • Push to the remote, and the PR shows that source/libs/icons.js has been deleted and source/libs/icons.tsx has been added.

I've even had one of the maintainers of the repo try to give me a hand, but he ends up in the same predicament as I do.

Any suggestions gitfolk?

Comment on DEV