Getting Git to Acknowledge Previously Moved Files
I think it already does this. Now, I could be wrong, but I've read that git tracks files based on their contents not based on their position in the file system or based on delta/differences. In the stack I think it shows it as if the files are being removed and the then re-added, but I think I've tried this once and it still maintained the history, due to the aforementioned way that git tracks things.
Still would be helpful for someone to verify if I'm correct or not. Sorry if I misunderstood your question.
To have git remove files that are removed or moved already, just enter
git add -u
To better understand why Git does do rename detection instead of (more common) explicit rename tracking, and how git log
path limiting works, you can read read Linus's ultimate content tracking tool blog post by Junio C Hamano, maintainer of Git (and references therein).
git
doesn't track the history of individual files and it doesn't treat moves and copies specially, that is there is no special metadata that indicates that a move or copy occurred. Instead each git commit is a complete snapshot of the working tree.
If you want to see moves in git log
you can supply -M
in addition to an option that lists which files have changed, e.g.
git log --summary -M
git
will look at the adjacent trees in the commit history and infer if any files where moved by each commit.
To find copies as well as renames you can use the -C
option, you can supply it twice to make git look harder for possible copy sources at the expense of some performance.
git log --summary -M -C -C
Note, that as git doesn't store file history (only commit history), even if you did git rm
and git mv
the file, you wouldn't lose any history. All changes to the path would still be recorded and visible in a git log
.