ご存じでしょうが、gitの店舗yourProject/.git/
フォルダの下のファイルのすべてのバージョン。
前にロールバックすることが可能であるがgitの履歴は、このようなreset --hard
、commit --amend
、rebase
などなどのコマンドによってreflog
のおかげで変更された場合でも、コミットします。
免責事項: gitの履歴が変更されると、一部のコミットがガベージコレクションの対象外となる分離状態になっている可能性があります。さらに進む前に、を強くお勧めします。〜バックアッププロジェクトディレクトリ全体またはそれらのコミットが完全に失われる可能性があります。 git documentationから
:
リファレンスログ、または「reflogs」、支店および他の参考文献の先端がローカルリポジトリで更新された記録。
コマンドgit reflog
は、履歴に加えられた変更を示しています。これにより、git reset
を希望の状態に戻し、不要なgit履歴の変更をロールバックすることができます。
例:
- 私は私が私が
test.txt
- にテキスト
world
を追加
- それをコミットコンテンツ
hello
- でファイル
test.txt
を作成する空のリポジトリ
- を作成私はコミットを修正する(これは以前のコミットを変更するものではなく、実際にはコミットする新しいコミットを作成します。前のコミットはまだ存在しますが、分離状態です)。
- 私は前のコミットを見つけるのに
git reflog
を使用します。
- 以前のコミットを復元するにはgit reset --hardを使用します。
出力:
/tmp/test [ mkdir /tmp/test
/tmp/test [ cd /tmp/test
/tmp/test [ git init
/tmp/test [ echo 'hello' >> test.txt
/tmp/test [ git add test.txt
/tmp/test [ git commit -m 'First commit'
[master (root commit) 60292e4] First commit
1 file changed, 1 insertion(+)
create mode 100644 test.txt
/tmp/test [ echo 'world' >> test.txt
/tmp/test [ git commit --amend -m 'oops'
[master 76ce76f] oops
1 file changed, 1 insertion(+)
create mode 100644 test.txt
/tmp/test [ git reflog
76ce76f [email protected]{0}: commit (amend): oops
60292e4 [email protected]{1}: commit (initial): First commit
/tmp/test [ git reset --hard 60292e4
/tmp/test cat test.txt
hello
何かする前に、プロジェクトディレクトリの完全なコピーを作成します。あなたのファイルはあなたの '.git'フォルダに残っているかもしれませんが、削除が可能かもしれません。 –
そして、 'git reflog'コマンドを実行してみてください。 https://git-scm.com/docs/git-reflog –
あなたは正しいと思われますが、プロジェクトフォールドはまだ約3Gbのサイズです。それを今バックアップしました。 'git reflog'は私に多くの_checkoutを示しました:マスターからマスター_に移動します。 – Chriz