I would like to rename/move a project subtree in Git moving it from
/project/xyz
to
/components/xyz
If I use a plain git mv project components, then all the commit history for the xyz project gets lost. Is there a way to move this such that the history is maintained?
Git detects renames rather than persisting the operation with the commit, so whether you use git mv or mv doesn't matter, as long as the move operation is committed separately from any changes to the file.
The log command takes a --follow argument that continues history before a rename operation, i.e., it searches for similar content using heuristics.
To lookup the full history, use the following command:
git log --follow ./path/to/file