Skip to content
Menu
メモ
  • ホーム
  • 開発技術
    • サーバー構築関係
      • 公開サーバー構築
      • ドメイン・サーバー
    • プログラム開発
      • Docker
    • 人工知能
  • ライフスタイル
    • 投資
      • 株式
    • お得
      • クレジットカード
  • ビジネスサポート
    • 会社経営
    • 経理
    • サンプルページ
  • 人間の肉体をコントロールする
メモ

Git featue作ったらコミットしていたデータが消えた

Posted on 2022年6月23日

コミットしていたデータが消えた

ソースツリー上に見えない! 消したか!

あきらめて、3日分のプログラムを作り直そうと思ったが、あきらめが悪いオラはググってみた

ああぁ~ある! git でコミットが消えた場合に簡単に復帰する方法

以下のコマンドを入力し、これまでのLogを確認

git reflog

$ git reflog
1058ff2 (HEAD -> develop, origin/develop) HEAD@{0}: checkout: moving from feature/#_AAA to develop
43c59d0 (origin/feature/#BBB, feature/#_AAA, feature/#BBB) HEAD@{1}: Branch: renamed refs/heads/feature/#_コメントZ to refs/heads/feature/#_AAA
43c59d0 (origin/feature/#BBB, feature/#_AAA, feature/#BBB) HEAD@{3}: checkout: moving from c99c9d4ddfc26ae6ee30e71f22da9a069f8bc7e6 to feature/#_コメントY
c99c9d4 HEAD@{4}: commit: コメントX
63a3b60 HEAD@{5}: commit: コメントR
259b9a1 HEAD@{6}: commit: コメントP
aba1705 HEAD@{7}: checkout: moving from feature/#BBB to aba1705a37bd6d42bf1bdce7c87d73156eb8f4cd
43c59d0 (origin/feature/#BBB, feature/#_AAA, feature/#BBB) HEAD@{8}: reset: moving to HEAD
43c59d0 (origin/feature/#BBB, feature/#_AAA, feature/#BBB) HEAD@{9}: revert: Revert "コメントA"
23704a2 HEAD@{10}: commit: コメントA
aba1705 HEAD@{11}: commit: コメントB
0b69ee9 HEAD@{12}: revert: Revert "コメントC"
d99de67 HEAD@{13}: commit: コメントC

有った!

最後にコミットした「コメントX」

「コメントX」に戻し、新規featureを作る

git checkout c99c9d4

$ git checkout c99c9d4
Note: switching to 'c99c9d4'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at c99c9d4 コメントX
$ 

sourceTreeを見てみたが何も変わってない??

branchまで作ってみるか? 

MyBranchというbranchを作るために以下のコマンド実行

git branch MyBranch

$ git branch MyBranch

sourceTreeを見てみたが何も変わってない??

そうだ! 再起動だ!

おぉ、出た出た! 一安心

参考:git でコミットが消えた場合に簡単に復帰する方法

コメントを残す コメントをキャンセル

メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です

最近の投稿

  • クレジットカード
  • 教育訓練費・税額控除
  • タスクの優先順位の付け方や進め方
  • 会社へ出社した方が良い理由
  • 中間管理職

最近のコメント

  • Hello world! に WordPress コメントの投稿者 より

アーカイブ

  • 2025年3月
  • 2025年2月
  • 2025年1月
  • 2024年12月
  • 2024年11月
  • 2024年10月
  • 2024年9月
  • 2024年8月
  • 2024年7月
  • 2024年6月
  • 2024年5月
  • 2024年4月
  • 2024年3月
  • 2024年2月
  • 2024年1月
  • 2023年12月
  • 2023年11月
  • 2023年10月
  • 2023年9月
  • 2023年8月
  • 2023年7月
  • 2023年6月
  • 2023年5月
  • 2023年4月
  • 2023年3月
  • 2023年2月
  • 2023年1月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年7月
  • 2021年6月
  • 2021年5月
  • 2021年4月

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org
©2025 メモ | WordPress Theme: EcoCoded