Git: copy files keeping history
Make copies of a file while preserving git history, so that
git blame can find the original commits.
git blame heuristically walks the history to recover which commits were responsible for different parts of a file.
Its heuristics usually work if you move a file, but doesn't if you copy it: the copy will appear to have been created ex nihilo by the commit.
This script makes copies of a file using
git mv but keeps the original, which is then moved back to its original name. By keeping this complete history,
git blame is able to walk back to the original commits, in both the copies and the original.
Note that this will add N+3 commits to the history, where N is the number of new copies.
The use case is when you need to split a file into pieces: make a history-preserving copy of the original for each piece, then delete the extraneous parts in each copy.