LoginSignup
43
49

More than 5 years have passed since last update.

Gitで過去に削除してコミットしたファイルを復元する

Posted at

いらないとおもって消したけどやっぱり必要だったっていうことがありましてね。

削除してコミットしたファイルを復元する方法

削除したファイルを見つける

git logで削除前のコミットIDをメモ。
git diff HEAD <コミットID> --name-onlyで変更したファイルを確認して、ファイル名をメモ。

復元する

git checkout <commit> -- <FILE_PATH> でファイルが今いるブランチに復元されてステージされます。

bash
git checkout 32603a3 -- /var/www/app/models/ImportantFile.js
bash
[root@localhost models]# git st
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   ./ImportantFilejs
[root@localhost models]#

感想

Gitって本当にすばらしいですねぇ~
さよなら、さよなら、さよなら!


43
49
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
43
49