Context
I often move, rename files in Visual Studio 2022. Rename is a standard refactoring practice. However when I rename a file in Solution Explorer, not git mv
operation is performed, instead git delete and git add.
This causes loosing the history of that particular file/class, which is a great loss in many cases.
Question
I can do the move operation leaving the IDE and using command line
git mv myoldfile.cs mynewfile.cs
which will keep history perfectly, but leaving the IDE is a productivity killer, especially when talking about refactoring and renaming multiple classes/files.
How to perform git mv
within Visual Studio, instead of git delete and git add, when renaming, moving files in Solution Explorer?
git
does not have a concept of "move" or "rename". Remember: a git commit is a snapshot, not a diff/delta. – Bolshevistgit mv
doesn't store anything "special" or unique in your repo? A gitmv
is identical to physically moving files yourself or by any other tool. That's why there's no IDE support for it: because it simply isn't needed. – Bolshevistgit
's built-in move-detection logic). And there are plenty of operations in VS that trigger a filesystem move-or-rename that the Solution Explorer will show as delete-and-new and plenty that make Solution Explorer show as an actual move. If you encounter differences, blame the heuristics (which can change between individual VS releases). – Bolshevist