前回の記事で過去のコミットに遡って修正を行う方法を紹介しましたが,これをstashと組み合わせると過去のコミットに新しく加えた変更を追加することができます.
$ git status
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: test.txt
より,test.txtに変更が新しく加えられようとしているところで,
$ git stash
とすると変更を一時的に待避することができます. その後
$ git rebase -i
などで変更を加えたいコミットまで遡ったあと
$ git stash pop
とすると待避させた変更を取り出すことができます.


