0

I have a file called, say, Alpha.cs, and I want to rename it to, say, Aleph.cs. I already renamed it in Visual Studio and committed/pushed, and I'm trying to create a pull request. But the person who's reviewing the changes says that I've erased all the history of the file because Visual Studio's git integration is broken and when you rename a file there, it actually deletes and re-adds it, destroying the history.

So is there any way to retroactively turn this delete/add into a rename operation? I could of course make a new branch, do the rename manually using git mv Alpha.cs Aleph.cs, commit, copy in all the other changes, commit again, push, and make a new pull request, abandoning the existing one. But that seems rather tedious and error prone. There's got to be a better way...

ekolis
  • 6,270
  • 12
  • 50
  • 101
  • https://stackoverflow.com/a/45155912/7976758, https://stackoverflow.com/a/54012023/7976758 – phd Feb 23 '21 at 15:13
  • 1
    well.... just a side comment: it's not like visual studio destroys anything. to git, it will see if the file was renamed (certain conditions apply, just in case). It's just that visual studio's engine (libgit2, whatever) fails to track it. – eftshift0 Feb 23 '21 at 15:15
  • and sure.... you can rewrite history of the file so that it shows up with a different name from the get go... but it has a price tag. Rewriting history is not a beautiful thing.... not that it's too ugly.... I think that people who know their way around git can handle it gracefully... but even if you have all git-masters around you, it still requires coordination so that people are aware of a branch will get history rewritten. – eftshift0 Feb 23 '21 at 15:16
  • VS2019 uses `mingitw`, basically automating the calling of `git.exe`. Visual Studio will track exactly what git tracks. Git uses the file contents to track renames. There is no registration of a rename in the git index, it's inferred: https://stackoverflow.com/a/2641227/736079 – jessehouwing Feb 23 '21 at 16:20

0 Answers0