👯‍♀️

Git のファイルを履歴付きでコピーしたい

に公開

大きくなりすぎたソースファイルを分割したいときなど、単純にファイル複製すると片方で commit 履歴が失われてしまう。

以下のような手順で履歴を失わずにファイルを複製することができる。

手順

$ git mv org.txt cpy.txt
$ git stash
$ git mv org.txt org.txt.tmp
$ git stash
$ git stash pop
$ git stash pop
$ git commit -a
$ git mv org.txt.tmp org.txt
$ git commit -a

確認

$ git blame cpy.txt
$ git log --follow cpy.txt

フォルダでもOK

参考

Discussion