views:

565

answers:

4

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 file history for the xyz project gets lost.

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

+1  A: 
git log --follow [file]

will show you the history through renames.

Erik Hesselink
+6  A: 

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):

http://www.kernel.org/pub/software/scm/git/docs/git-log.html

To lookup the full history use the following command:

git log --follow ./path/to/file
troethom
It would be nice not to need the --follow but I guess this will have to do. Thanks for your answer.
sgargan
I suspect this is a performance consideration. If you don't need the full history, it will sure take longer time scanning the content. The easiest way is to setup an alias `git config alias.logf "log --follow"` and just write `git logf ./path/to/file`.
troethom
I like that alot! Thanks for the tip.
sgargan
But which path do you specify, the old path or the new path? And if ti's the old path, how do you know to specify the old path?
Joseph Kingry
You should just use the new path. It works the way that Git traverses back through history and switches to the old path, when a rename is detected.
troethom
A: 

It is not working for me.

I want to retain the old history of a file which was renamed to new name.

Please let me know if there is a way.

-Jee

jee
Note that git uses the content of the file to detect renames. If you have substantially rewritten the content, then the rename tracking won't work. You can adjust the sensitivity, but offhand I don't know the syntax.
Benjol
is it possible to copy the old history of a file to another file i.e. renamed file history to new name.I was trying with copy and replace the file name to point the history to the newly renamed file. is it possible with GIT.Please let me know if there is a way to do this using external scripts and maitaining the history for renamed file.-Jee
jee
A: 

is it possible to copy the old history of a file to another file i.e. renamed file history to new name. I was trying with copy and replace the file name to point the history to the newly renamed file. is it possible with GIT.

Please let me know if there is a way to do this using external scripts and maitaining the history for renamed file.

-Jee

jee