views:

44

answers:

3

I want to take a function out of one file and put it into another, but keep the blame history.

cp a.php b.php

vim b.php
# delete everything but 1 function

vim a.php
# delete the 1 function

git add a.php b.php
git commit

But if I run git blame b.php I only see it blaming to this new commit.

+1  A: 

Perhaps this previous SO question could be informative:

http://stackoverflow.com/questions/1728922/how-does-git-track-source-code-moved-between-files

To paraphrase the accepted answer: essentially, Git doesn't actually "store" moved code; when generating things like blames for moved code, that's done ex post facto by examining the state of the entire repository from commit to commit.

Amber
A: 

try git blame -C -C b.php

max
I want the history to actually blame to the older commits. We use git-svn so others will be on svn.
Paul Tarjan
Too bad. SVN doesn't support this, at all!
Arafangion
A: 

This may be a stupid question, but did in your example you only did:

git add b.php

What if you try adding git add a.php too? I think it will track that the function has just been moved.

iand675
Sorry yes, I did add a.php and b.php.
Paul Tarjan