在git push-f之后恢复github存储库中删除的文件

在git push-f之后恢复github存储库中删除的文件,git,github,Git,Github,有一个Github存储库(我不是存储库的创建者),我添加了一个文件并执行了git push-f命令。结果,除了我添加和推送的文件外,存储库中的所有文件/包都被删除。我尝试通过git revert还原所有已删除的文件,但它没有还原所有已删除的文件。是否有办法恢复所有已删除的文件?TL;博士 使用git reflog获取已删除提交的哈希值 使用git checkout签出/选择提交 使用git分支恢复1;git checkout recover1创建指向已删除/已恢复提交的分支 对恢复的分支执行一

有一个Github存储库(我不是存储库的创建者),我添加了一个文件并执行了git push-f命令。结果,除了我添加和推送的文件外,存储库中的所有文件/包都被删除。我尝试通过git revert还原所有已删除的文件,但它没有还原所有已删除的文件。是否有办法恢复所有已删除的文件?

TL;博士
  • 使用
    git reflog
    获取已删除提交的哈希值
  • 使用
    git checkout
    签出/选择提交
  • 使用
    git分支恢复1;git checkout recover1
    创建指向已删除/已恢复提交的分支
  • 对恢复的分支执行一些操作(例如:重新设置对此分支所做的更改,或将分支推送到github,或将master指向恢复的分支)
我创建了一个存储库来测试:

准备: 我的情景 本回购协议应包含此类历史记录:

(initial_commit) <- (commit_1) <- (commit_2_bad) <- (commit_3) <- [master,head]
                               <- (commit_2_good)
每次提交都会在根目录中创建一个带有提交名称的空文件(除了只创建README.md的
initial\u commit

有关如何完成、运行什么命令以及输出内容的步骤将在wiki中编写,而不是在存储库/源代码中编写

台阶
  • 在github中创建名为Kristian Tan/coba recover forced push的新存储库
  • 通过github的web界面创建新文件README.md,并将其作为“初始提交”提交
  • 开放式终端
  • 先发制人
  • 进行第二次提交(良好)
  • 进行第二次提交(错误)
  • 作出第三次承诺
尝试1:使用
  • 尝试恢复第二次正确提交
  • 发现感兴趣的事件:
  • 我们得到了一个commit_2_good hash值为
    4a3f751423e750326c463ac400812a4f51f768a8
  • 尝试创建指向该哈希的新分支
  • 我们似乎无法为该提交创建引用(分支)(可能我在某个地方犯了错误,或者该分支已经被github永久删除,因为它已经被强制推送了)
尝试2:使用
git reflog
git checkout
收回提交
  • 另一种尝试:使用
    git reflog
恢复
  • 通过创建分支进行恢复
  • 交互式终端显示GNU Nano(因为它是我的默认文本编辑器),编辑文件(注释掉
    commit\u 2\u bad
GNU nano 5.6.1/tmp/coba-recover-forced-push-1/.git/rebase merge/git-rebase todo-Modified
#选择a123eb8提交2错误
选择00db663提交3
#将3baa9f0..00db663重设为3baa9f0的基础(2个命令)
#
#命令:
#p,pick=使用提交
#r,reword=使用提交,但编辑提交消息
#e,edit=使用提交,但停止修改
#s,squash=使用提交,但合并到以前的提交中
#f,fixup=类似于“squash”,但丢弃此提交的日志消息
#x,exec=使用shell运行命令(行的其余部分)
#b,break=stop here(稍后用'git rebase--continue'继续重新基址)
#d,drop=remove-commit
#l,label=用名称标记当前磁头
#t,重置=将磁头重置为标签
#m,合并[-C |-C][#]
# .       使用原始合并提交的
# .       消息(如果没有原始合并提交,则为单行)
#。已指定)。使用-c重写提交消息。
#
#这些线路可以重新订购;它们是从上到下执行的。
#
#如果在此处删除一行,则提交将丢失。
#
#但是,如果您删除了所有内容,则重新基础将中止。
#
  • 结果:
已成功重新设置基准并更新了参考文件/头文件/主文件。
$git日志
提交726b9ca742619c59ed7efa7f3ae0d1fc9a5aaf13(主机->主机)
作者:克里斯蒂安
日期:4月7日星期三15:34:50 2021+0700
承诺3
提交4a3f751423e750326c463ac400812a4f51f768a8(恢复1)
作者:克里斯蒂安
日期:4月7日星期三15:31:38 2021+0700
做得好
提交87AAFEC7DDCB2614255CFE00CE74BA3B7D51C66F4
作者:克里斯蒂安
日期:4月7日星期三15:29:30 2021+0700
承诺1
提交15927842CAC8305BEBF810D83C42F7574C17537
作者:克里斯蒂安·塔努维加亚
日期:4月7日星期三15:25:45 2021+0700
初始提交
尝试以下步骤(全部3个步骤):

  • 使用
    git reflog
    命令识别回购的最后一个已知良好状态
  • 然后,
    git reset——很难恢复到它
  • 然后,另一个
    git push--force
    将远程存储库重置回该状态

  • 您还可以在

    上找到一些详细信息,您可以检查
    git checkout
    并手动复制该文件,然后移回您的分支并粘贴该文件。试试这个:它基本上是使用github的API获取提交哈希(通过查看repo的事件历史记录),然后使用另一个github API创建指向选定对象的新分支hash@StanislavBashkyrtsev存储库中只有一个分支,它只有我推送的文件,但原始提交和删除的文件仍在本地repo中。因此,首先需要签出该提交,然后才能再次签出唯一的分支并再次提交该文件。
    (initial_commit) <- (commit_1) <- (commit_2_good) <- (commit_3) <- [master,head]
    
    $ cd /tmp
    $ git clone git@github.com:Kristian-Tan/coba-recover-forced-push.git
    
    Cloning into 'coba-recover-forced-push'...
    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Compressing objects: 100% (2/2), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Receiving objects: 100% (3/3), done.
    
    $ cd /tmp/coba-recover-forced-push
    
    $ touch commit_1
    $ git add .
    $ git commit -m 'commit_1'
    
    [master 87aafec] commit_1
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 commit_1
    
    $ git push origin master
    
    Enumerating objects: 4, done.
    Counting objects: 100% (4/4), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 281 bytes | 281.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    To github.com:Kristian-Tan/coba-recover-forced-push.git
       1592784..87aafec  master -> master
    
    $ touch commit_2_good
    $ git add .
    $ git commit -m 'commit_2_good'
    
    [master 4a3f751] commit_2_good
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 commit_2_good
    
    $ git push origin master
    
    Enumerating objects: 3, done.
    Counting objects: 100% (3/3), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (2/2), 287 bytes | 287.00 KiB/s, done.
    Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
    To github.com:Kristian-Tan/coba-recover-forced-push.git
       87aafec..4a3f751  master -> master
    
    $ rm commit_2_good 
    $ touch commit_2_bad
    $ git add .
    $ git commit --amend -m 'commit_2_bad'
    
    [master 52710b6] commit_2_bad
     Date: Wed Apr 7 15:31:38 2021 +0700
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 commit_2_bad
    
    $ git push --force origin master
    
    Enumerating objects: 3, done.
    Counting objects: 100% (3/3), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (2/2), 287 bytes | 287.00 KiB/s, done.
    Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
    To github.com:Kristian-Tan/coba-recover-forced-push.git
     + 4a3f751...52710b6 master -> master (forced update)
    
    $ touch commit_3
    $ git add .
    $ git commit -m 'commit_3'
    
    [master 726b9ca] commit_3
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 commit_3
    
    $ git push origin master
    
    Enumerating objects: 3, done.
    Counting objects: 100% (3/3), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (2/2), 254 bytes | 254.00 KiB/s, done.
    Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
    remote: Resolving deltas: 100% (1/1), completed with 1 local object.
    To github.com:Kristian-Tan/coba-recover-forced-push.git
       52710b6..726b9ca  master -> master
    
    $ curl -u Kristian-Tan https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push/events
    Enter host password for user 'Kristian-Tan':
    [
      {
        "id": "15843469917",
        "type": "GollumEvent",
        "actor": {
          "id": 18624029,
          "login": "Kristian-Tan",
          "display_login": "Kristian-Tan",
          "gravatar_id": "",
          "url": "https://api.github.com/users/Kristian-Tan",
          "avatar_url": "https://avatars.githubusercontent.com/u/18624029?"
        },
        "repo": {
          "id": 355466035,
          "name": "Kristian-Tan/coba-recover-forced-push",
          "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push"
        },
        "payload": {
          "pages": [
            {
              "page_name": "Home",
              "title": "Home",
              "summary": null,
              "action": "edited",
              "sha": "7b7c0e0d954d9763c71e1dd4deacad5a9f7293c9",
              "html_url": "https://github.com/Kristian-Tan/coba-recover-forced-push/wiki/Home"
            }
          ]
        },
        "public": true,
        "created_at": "2021-04-07T08:35:32Z"
      },
      {
        "id": "15843462908",
        "type": "PushEvent",
        "actor": {
          "id": 18624029,
          "login": "Kristian-Tan",
          "display_login": "Kristian-Tan",
          "gravatar_id": "",
          "url": "https://api.github.com/users/Kristian-Tan",
          "avatar_url": "https://avatars.githubusercontent.com/u/18624029?"
        },
        "repo": {
          "id": 355466035,
          "name": "Kristian-Tan/coba-recover-forced-push",
          "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push"
        },
        "payload": {
          "push_id": 6863056879,
          "size": 1,
          "distinct_size": 1,
          "ref": "refs/heads/master",
          "head": "726b9ca742619c59ed7efa7f3ae0d1fc9a5aaf13",
          "before": "52710b6e7c0383382444ec0d2242b26be38adb58",
          "commits": [
            {
              "sha": "726b9ca742619c59ed7efa7f3ae0d1fc9a5aaf13",
              "author": {
                "email": "myemail@myprovider",
                "name": "Kristian"
              },
              "message": "commit_3",
              "distinct": true,
              "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push/commits/726b9ca742619c59ed7efa7f3ae0d1fc9a5aaf13"
            }
          ]
        },
        "public": true,
        "created_at": "2021-04-07T08:35:03Z"
      },
      {
        "id": "15843442050",
        "type": "GollumEvent",
        "actor": {
          "id": 18624029,
          "login": "Kristian-Tan",
          "display_login": "Kristian-Tan",
          "gravatar_id": "",
          "url": "https://api.github.com/users/Kristian-Tan",
          "avatar_url": "https://avatars.githubusercontent.com/u/18624029?"
        },
        "repo": {
          "id": 355466035,
          "name": "Kristian-Tan/coba-recover-forced-push",
          "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push"
        },
        "payload": {
          "pages": [
            {
              "page_name": "Home",
              "title": "Home",
              "summary": null,
              "action": "edited",
              "sha": "ae82df1e2efd947d5e9257f8f5a49c3cc61443de",
              "html_url": "https://github.com/Kristian-Tan/coba-recover-forced-push/wiki/Home"
            }
          ]
        },
        "public": true,
        "created_at": "2021-04-07T08:33:32Z"
      },
      {
        "id": "15843439721",
        "type": "PushEvent",
        "actor": {
          "id": 18624029,
          "login": "Kristian-Tan",
          "display_login": "Kristian-Tan",
          "gravatar_id": "",
          "url": "https://api.github.com/users/Kristian-Tan",
          "avatar_url": "https://avatars.githubusercontent.com/u/18624029?"
        },
        "repo": {
          "id": 355466035,
          "name": "Kristian-Tan/coba-recover-forced-push",
          "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push"
        },
        "payload": {
          "push_id": 6863045743,
          "size": 1,
          "distinct_size": 1,
          "ref": "refs/heads/master",
          "head": "52710b6e7c0383382444ec0d2242b26be38adb58",
          "before": "4a3f751423e750326c463ac400812a4f51f768a8",
          "commits": [
            {
              "sha": "52710b6e7c0383382444ec0d2242b26be38adb58",
              "author": {
                "email": "myemail@myprovider",
                "name": "Kristian"
              },
              "message": "commit_2_bad",
              "distinct": true,
              "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push/commits/52710b6e7c0383382444ec0d2242b26be38adb58"
            }
          ]
        },
        "public": true,
        "created_at": "2021-04-07T08:33:22Z"
      },
      {
        "id": "15843418773",
        "type": "PushEvent",
        "actor": {
          "id": 18624029,
          "login": "Kristian-Tan",
          "display_login": "Kristian-Tan",
          "gravatar_id": "",
          "url": "https://api.github.com/users/Kristian-Tan",
          "avatar_url": "https://avatars.githubusercontent.com/u/18624029?"
        },
        "repo": {
          "id": 355466035,
          "name": "Kristian-Tan/coba-recover-forced-push",
          "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push"
        },
        "payload": {
          "push_id": 6863035508,
          "size": 1,
          "distinct_size": 1,
          "ref": "refs/heads/master",
          "head": "4a3f751423e750326c463ac400812a4f51f768a8",
          "before": "87aafec7ddcb261425cfe00ce74ba3b7d51c66f4",
          "commits": [
            {
              "sha": "4a3f751423e750326c463ac400812a4f51f768a8",
              "author": {
                "email": "myemail@myprovider",
                "name": "Kristian"
              },
              "message": "commit_2_good",
              "distinct": true,
              "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push/commits/4a3f751423e750326c463ac400812a4f51f768a8"
            }
          ]
        },
        "public": true,
        "created_at": "2021-04-07T08:31:52Z"
      },
      {
        "id": "15843394061",
        "type": "GollumEvent",
        "actor": {
          "id": 18624029,
          "login": "Kristian-Tan",
          "display_login": "Kristian-Tan",
          "gravatar_id": "",
          "url": "https://api.github.com/users/Kristian-Tan",
          "avatar_url": "https://avatars.githubusercontent.com/u/18624029?"
        },
        "repo": {
          "id": 355466035,
          "name": "Kristian-Tan/coba-recover-forced-push",
          "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push"
        },
        "payload": {
          "pages": [
            {
              "page_name": "Home",
              "title": "Home",
              "summary": null,
              "action": "edited",
              "sha": "6eb6ae58e3e71da932b3a89f58e8a4f68c81cb0b",
              "html_url": "https://github.com/Kristian-Tan/coba-recover-forced-push/wiki/Home"
            }
          ]
        },
        "public": true,
        "created_at": "2021-04-07T08:30:09Z"
      },
      {
        "id": "15843386894",
        "type": "PushEvent",
        "actor": {
          "id": 18624029,
          "login": "Kristian-Tan",
          "display_login": "Kristian-Tan",
          "gravatar_id": "",
          "url": "https://api.github.com/users/Kristian-Tan",
          "avatar_url": "https://avatars.githubusercontent.com/u/18624029?"
        },
        "repo": {
          "id": 355466035,
          "name": "Kristian-Tan/coba-recover-forced-push",
          "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push"
        },
        "payload": {
          "push_id": 6863020078,
          "size": 1,
          "distinct_size": 1,
          "ref": "refs/heads/master",
          "head": "87aafec7ddcb261425cfe00ce74ba3b7d51c66f4",
          "before": "15927842cac8305bebbf810d83c42f7574c17537",
          "commits": [
            {
              "sha": "87aafec7ddcb261425cfe00ce74ba3b7d51c66f4",
              "author": {
                "email": "myemail@myprovider",
                "name": "Kristian"
              },
              "message": "commit_1",
              "distinct": true,
              "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push/commits/87aafec7ddcb261425cfe00ce74ba3b7d51c66f4"
            }
          ]
        },
        "public": true,
        "created_at": "2021-04-07T08:29:39Z"
      },
      {
        "id": "15843359934",
        "type": "GollumEvent",
        "actor": {
          "id": 18624029,
          "login": "Kristian-Tan",
          "display_login": "Kristian-Tan",
          "gravatar_id": "",
          "url": "https://api.github.com/users/Kristian-Tan",
          "avatar_url": "https://avatars.githubusercontent.com/u/18624029?"
        },
        "repo": {
          "id": 355466035,
          "name": "Kristian-Tan/coba-recover-forced-push",
          "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push"
        },
        "payload": {
          "pages": [
            {
              "page_name": "Home",
              "title": "Home",
              "summary": null,
              "action": "created",
              "sha": "ad832555ceaec9b467c52f7c4e639f0675012eb8",
              "html_url": "https://github.com/Kristian-Tan/coba-recover-forced-push/wiki/Home"
            }
          ]
        },
        "public": true,
        "created_at": "2021-04-07T08:27:46Z"
      },
      {
        "id": "15843330684",
        "type": "CreateEvent",
        "actor": {
          "id": 18624029,
          "login": "Kristian-Tan",
          "display_login": "Kristian-Tan",
          "gravatar_id": "",
          "url": "https://api.github.com/users/Kristian-Tan",
          "avatar_url": "https://avatars.githubusercontent.com/u/18624029?"
        },
        "repo": {
          "id": 355466035,
          "name": "Kristian-Tan/coba-recover-forced-push",
          "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push"
        },
        "payload": {
          "ref": "master",
          "ref_type": "branch",
          "master_branch": "master",
          "description": null,
          "pusher_type": "user"
        },
        "public": true,
        "created_at": "2021-04-07T08:25:45Z"
      },
      {
        "id": "15843215446",
        "type": "CreateEvent",
        "actor": {
          "id": 18624029,
          "login": "Kristian-Tan",
          "display_login": "Kristian-Tan",
          "gravatar_id": "",
          "url": "https://api.github.com/users/Kristian-Tan",
          "avatar_url": "https://avatars.githubusercontent.com/u/18624029?"
        },
        "repo": {
          "id": 355466035,
          "name": "Kristian-Tan/coba-recover-forced-push",
          "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push"
        },
        "payload": {
          "ref": null,
          "ref_type": "repository",
          "master_branch": "master",
          "description": null,
          "pusher_type": "user"
        },
        "public": true,
        "created_at": "2021-04-07T08:17:44Z"
      }
    ]
    
    
      {
        "id": "15843418773",
        "type": "PushEvent",
        "actor": {
          "id": 18624029,
          "login": "Kristian-Tan",
          "display_login": "Kristian-Tan",
          "gravatar_id": "",
          "url": "https://api.github.com/users/Kristian-Tan",
          "avatar_url": "https://avatars.githubusercontent.com/u/18624029?"
        },
        "repo": {
          "id": 355466035,
          "name": "Kristian-Tan/coba-recover-forced-push",
          "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push"
        },
        "payload": {
          "push_id": 6863035508,
          "size": 1,
          "distinct_size": 1,
          "ref": "refs/heads/master",
          "head": "4a3f751423e750326c463ac400812a4f51f768a8",
          "before": "87aafec7ddcb261425cfe00ce74ba3b7d51c66f4",
          "commits": [
            {
              "sha": "4a3f751423e750326c463ac400812a4f51f768a8",
              "author": {
                "email": "myemail@myprovider",
                "name": "Kristian"
              },
              "message": "commit_2_good",
              "distinct": true,
              "url": "https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push/commits/4a3f751423e750326c463ac400812a4f51f768a8"
            }
          ]
        },
        "public": true,
        "created_at": "2021-04-07T08:31:52Z"
      },
    
    $ curl -u Kristian-Tan -X POST -d '{"ref":"refs/heads/recover1", "sha":"4a3f751423e750326c463ac400812a4f51f768a8"}' https://api.github.com/repos/Kristian-Tan/coba-recover-forced-push/git/refs
    
    Enter host password for user 'Kristian-Tan':
    {
      "message": "Not Found",
      "documentation_url": "https://docs.github.com/rest/reference/git#create-a-reference"
    }
    
    $ git reflog
    
    726b9ca (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: commit: commit_3
    52710b6 HEAD@{1}: commit (amend): commit_2_bad
    4a3f751 HEAD@{2}: commit: commit_2_good
    87aafec HEAD@{3}: commit: commit_1
    1592784 HEAD@{4}: clone: from github.com:Kristian-Tan/coba-recover-forced-push.git
    
    $ git checkout 4a3f751
    
    Note: switching to '4a3f751'.
    
    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 4a3f751 commit_2_good
    
    $ git status
    
    HEAD detached at 4a3f751
    nothing to commit, working tree clean
    
    $ ls -al
    
    total 4
    drwxr-xr-x  3 kristian kristian  120 Apr  7 15:57 .
    drwxrwxrwt 21 root     root      600 Apr  7 15:55 ..
    -rw-r--r--  1 kristian kristian    0 Apr  7 15:29 commit_1
    -rw-r--r--  1 kristian kristian    0 Apr  7 15:57 commit_2_good
    drwxr-xr-x  8 kristian kristian  280 Apr  7 15:57 .git
    -rw-r--r--  1 kristian kristian 1652 Apr  7 15:26 README.md
    
    $ git clone --branch 4a3f751 git@github.com:Kristian-Tan/coba-recover-forced-push.git
    
    Cloning into 'coba-recover-forced-push'...
    fatal: Remote branch 4a3f751 not found in upstream origin
    
    $ git clone --branch 4a3f751423e750326c463ac400812a4f51f768a8 git@github.com:Kristian-Tan/coba-recover-forced-push.git
    
    Cloning into 'coba-recover-forced-push'...
    fatal: Remote branch 4a3f751423e750326c463ac400812a4f51f768a8 not found in upstream origin
    
    $ git clone git@github.com:Kristian-Tan/coba-recover-forced-push.gitCloning into 'coba-recover-forced-push'...
    
    remote: Enumerating objects: 10, done.
    remote: Counting objects: 100% (10/10), done.
    remote: Compressing objects: 100% (7/7), done.
    remote: Total 10 (delta 2), reused 6 (delta 1), pack-reused 0
    Receiving objects: 100% (10/10), done.
    Resolving deltas: 100% (2/2), done.
    
    $ cd coba-recover-forced-push/
    $ git checkout 4a3f751423e750326c463ac400812a4f51f768a8
    
    fatal: reference is not a tree: 4a3f751423e750326c463ac400812a4f51f768a8
    
    $ git reflog
    
    726b9ca (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: clone: from github.com:Kristian-Tan/coba-recover-forced-push.git
    
    $ git checkout 4a3f751423e750326c463ac400812a4f51f768a8
    
    Note: switching to '4a3f751'.
    
    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 4a3f751 commit_2_good
    
    $ git branch recover1
    $ git checkout recover1
    
    Switched to branch 'recover1'
    
    
    $ git checkout master
    
    Switched to branch 'master'
    
    $ git rebase -i recover1
    
      GNU nano 5.6.1                                                                        /tmp/coba-recover-forced-push-1/.git/rebase-merge/git-rebase-todo                                                                         Modified  
    # pick a123eb8 commit_2_bad
    pick 00db663 commit_3
    
    # Rebase 3baa9f0..00db663 onto 3baa9f0 (2 commands)
    #
    # Commands:
    # p, pick <commit> = use commit
    # r, reword <commit> = use commit, but edit the commit message
    # e, edit <commit> = use commit, but stop for amending
    # s, squash <commit> = use commit, but meld into previous commit
    # f, fixup <commit> = like "squash", but discard this commit's log message
    # x, exec <command> = run command (the rest of the line) using shell
    # b, break = stop here (continue rebase later with 'git rebase --continue')
    # d, drop <commit> = remove commit
    # l, label <label> = label current HEAD with a name
    # t, reset <label> = reset HEAD to a label
    # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
    # .       create a merge commit using the original merge commit's
    # .       message (or the oneline, if no original merge commit was
    # .       specified). Use -c <commit> to reword the commit message.
    #
    # These lines can be re-ordered; they are executed from top to bottom.
    #
    # If you remove a line here THAT COMMIT WILL BE LOST.
    #
    # However, if you remove everything, the rebase will be aborted.
    #
    
    
    Successfully rebased and updated refs/heads/master.
    
    $ git log
    
    commit 726b9ca742619c59ed7efa7f3ae0d1fc9a5aaf13 (HEAD -> master)
    Author: Kristian <myemail@myprovider>
    Date:   Wed Apr 7 15:34:50 2021 +0700
    
        commit_3
    
    commit 4a3f751423e750326c463ac400812a4f51f768a8 (recover1)
    Author: Kristian <myemail@myprovider>
    Date:   Wed Apr 7 15:31:38 2021 +0700
    
        commit_2_good
    
    commit 87aafec7ddcb261425cfe00ce74ba3b7d51c66f4
    Author: Kristian <myemail@myprovider>
    Date:   Wed Apr 7 15:29:30 2021 +0700
    
        commit_1
    
    commit 15927842cac8305bebbf810d83c42f7574c17537
    Author: Kristian Tanuwijaya <myemail@myprovider>
    Date:   Wed Apr 7 15:25:45 2021 +0700
    
        initial_commit