繁体   English   中英

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

[英]Restore deleted files in github repository after git push -f

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

TL;博士

  • 使用git reflog来获取已删除提交的 hash
  • 使用git checkout <hash>来签出/选择该提交
  • 使用git branch recover1; git checkout recover1 git branch recover1; git checkout recover1创建一个指向已删除/恢复的提交的分支
  • 对恢复的分支做一些事情(例如:重新调整对这个分支的更改,或者将分支推送到 github,或者将 master 指向恢复的分支)

我创建了一个存储库来测试这个: https://github.com/Kristian-Tan/coba-recover-forced-push

准备:

我的场景

这个 repo 应该包含这样的历史:

(initial_commit) <- (commit_1) <- (commit_2_bad) <- (commit_3) <- [master,head]
                               <- (commit_2_good)

commit commit 2 good将被 commit commit 2 bad替换(通过强制推送)

这里的目标是恢复提交 2,并使历史记录如下:

(initial_commit) <- (commit_1) <- (commit_2_good) <- (commit_3) <- [master,head]

每个提交将在根目录中创建一个带有其提交名称的空文件( initial_commit除外,它只创建 README.md)

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

脚步

  • 在 github 中创建名为 Kristian-Tan/coba-recover-forced-push 的新存储库
  • 通过 github 的 web 接口创建新文件 README.md 并将其提交为 'initial_commit'
  • 打开终端
$ 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

尝试1:使用https://gist.github.com/agarwalparas/d355a950148702cc7ba82abc4d1943bf

  • 尝试恢复第二次良好的提交
$ 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"
  },
  • 我们得到了 commit_2_good 有 hash 的4a3f751423e750326c463ac400812a4f51f768a8
  • 尝试创建一个指向该 hash 的新分支
$ 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"
}
  • 似乎我们无法为该提交创建引用(分支)(也许我在某处犯了错误,或者分支已经被 github 永久删除,因为它已经被强制推送)

尝试 2:使用git refloggit checkout来取回提交

  • 另一种尝试:使用git reflog
$ 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 reflog似乎是成功的,但是你必须在你强制推送的本地存储库中运行它(你不能从新克隆的存储库运行它)

  • 尝试从您强制推送的本地存储库外部恢复(失败)

$ 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'

  • 变基以获得所需的历史记录(initial_commit) <- (commit_1) <- (commit_2_good) <- (commit_3) <- [master,head]
$ git checkout master

Switched to branch 'master'

$ git rebase -i recover1
  • 交互式终端显示 GNU Nano(因为它是我的默认文本编辑器),编辑文件(注释掉commit_2_bad
  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

尝试以下步骤(全部 3 个):

  1. 使用git reflog命令识别 repo 的 last-known-good state
  2. 然后, git reset --hard <commit>恢复到它
  3. 然后,另一个git push --force将远程存储库重置回该 state

您还可以在这篇文章中找到一些详细信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM