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.
The general rule to maintaining blame history is to make a separate move commit first before any edits. It has been my experience that this allows git blame
to work without the need for the -C
option. So in the case of splitting the file up into new files, this can be done in two commits:
In the example provided, this would be:
cp a.php b.php
mv a.php c.php
git add a.php b.php c.php
git commit
vim b.php # delete everything but 1 function
vim c.php # delete the 1 function
git add b.php c.php
git commit