Github delete branch even after made commits to it?

风流意气都作罢 提交于 2019-12-06 09:57:05

问题


I have a github repo and I am working on the site, I don't know how to do command line stuff.

So I have a branch I made commits too. And I see it can be deleted. This is kind of nice. I always do small unit tests and just want to delete it. So if I do delete a branch is all traces and history of it gone?


回答1:


If you don't have a local repo anymore (meaning you cannot get your deleted branch through the local git reflog and push it back to GitHub), you still can retrieve (for a limited time, 90 days by default), your deleted branch from the GitHub repo itself.

See the GitHub Events API.
Those events are limited in time, so "all traces and history of it gone?": yes, eventually.

curl https://api.github.com/repos/<user>/<repo>/events

As described in this blog post, you will get a JSON payload which will include any push event you ever made, including your old branch:

    "id": "1970551769",
    "type": "PushEvent",
    "actor": {
      "id": 563541,
      "login": "<user>",
      "gravatar_id": "<id>",
      "url": "https://api.github.com/users/<user>",
      "avatar_url": "<url>"
    },
    "repo": {
      "id": 9652839,
      "name": "<user>/<repo>",
      "url": "https://api.github.com/repos/<user>/<repo>"
    },
    "payload": {
      "push_id": 303837533,
      "size": 1,
      "distinct_size": 1,
      "ref": "refs/heads/<branch>",  <============================
      "head": "a973ddd28d599c9ba128de56182f8769d2b9843b",
      "before": "4ef3d74316c04c892d17250f0ba251b328274e5f",
      "commits": [
        {
          "sha": "384f275933d5b762cdb27175aeff1263a8a7b7f7",
          "author": {
            "email": "<email>",
            "name": "<author>"
          },
          "message": "<commit message>",
          "distinct": true,
          "url": "https://api.github.com/repos/<user>/<repo>/commits/384f275933d5b762cdb27175aeff1263a8a7b7f7"
        }
      ]
    },
    "public": false,
    "created_at": "2014-02-06T14:05:17Z"
}

You can then fetch, using that specific commit 'a973ddd28d599c9ba128de56182f8769d2b9843b', make a branch locally and push it back to GitHub!

git fetch origin a973ddd28d599c9ba128de56182f8769d2b9843b:refs/remotes/origin/yourOldBranch
git checkout -b yourOldBranch
git push


来源:https://stackoverflow.com/questions/23850490/github-delete-branch-even-after-made-commits-to-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!