sgargan sgargan - 1 year ago 122
Git Question

Is it possible to move/rename files in git and maintain their history?

I would like to rename/move a project subtree in Git moving it from




If I use a plain
git mv project components
then all the file history for the
xyz project
gets lost.

Is there a way to move this such that the history is maintained?

Answer Source

Git detects renames rather than persisting the operation with the commit, so whether you use git mv or just a plain mv doesn't matter.

The log command, however, takes a --follow argument that continues history before a rename operation (that is, it searches for similar content using the heuristics):

To lookup the full history use the following command:

git log --follow ./path/to/file
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download