Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create an API access token.
    Through the Personal Settings panel on github, create a Personal Access Token (https://github.bath.ac.uk/settings/tokens), giving access to repo. Copy it off - it'll be a long hex string, and will grant access to the API using curl on the command line.

  2. Query the events API to find the push that created the commit you are trying to retrieve. In our case, we needed to locate the push which contained commit C.
    Use the following command:  

    Code Block
    themeEmacs
    languagebash
    curl https://github.bath.ac.uk/api/v3/repos/digital/<repo>/events -u <username>:<access-token>


    github will respond with JSON describing the last several actions, each one looking like this:

    Code Block
    themeEmacs
      {
        "id": "101029",
        "type": "PushEvent",
        "actor": {
          "id": 21,
          "login": "ej217",
          "display_login": "ej217",
          "gravatar_id": "",
          "url": "https://github.bath.ac.uk/api/v3/users/ej217",
          "avatar_url": "https://github.bath.ac.uk/avatars/u/21?"
        },
        "repo": {
          "id": 254,
          "name": "digital/cms-editor",
          "url": "https://github.bath.ac.uk/api/v3/repos/digital/cms-editor"
        },
        "payload": {
          "push_id": 70499,
          "size": 2,
          "distinct_size": 1,
          "ref": "refs/heads/staging",
          "head": "39ff6b51819ea4fc0634fcf850f80d8fdc7375ba",
          "before": "ffed42e68e0429206262b9692a14e4c1156fdc4e",
          "commits": [
            {
              "sha": "1ef781667898872fb443a8ba2336687cd5e74738",
              "author": {
                "email": "jk832@bath.ac.uk",
                "name": "Justin Keevill"
              },
              "message": "Componentise contacts",
              "distinct": false,
              "url": "https://github.bath.ac.uk/api/v3/repos/digital/cms-editor/commits/1ef781667898872fb443a8ba2336687cd5e74738"
            },
            {
              "sha": "39ff6b51819ea4fc0634fcf850f80d8fdc7375ba",
              "author": {
                "email": "E.Jennings@bath.ac.uk",
                "name": "Elizabeth Jennings"
              },
              "message": "Merge pull request #632 from digital/componentise-contacts\n\n[#153474723] Componentise contacts",
              "distinct": true,
              "url": "https://github.bath.ac.uk/api/v3/repos/digital/cms-editor/commits/39ff6b51819ea4fc0634fcf850f80d8fdc7375ba"
            }
          ]
        },
        "public": false,
        "created_at": "2017-12-13T14:38:34Z",
        "org": {
          "id": 7,
          "login": "digital",
          "gravatar_id": "",
          "url": "https://github.bath.ac.uk/api/v3/orgs/digital",
          "avatar_url": "https://github.bath.ac.uk/avatars/u/7?"
        }
      }
    
    

    By searching for the commit message of the lost commit, (for instance, "Componentise contacts"), identify its sha (for instance, "1ef781667898872fb443a8ba2336687cd5e74738")

  3. POST to the events API to create a branch from the lost sha.
    Use the following command: 

    Code Block
    themeEmacs
    languagebash
    curl -i  -u <username>:<access-token> -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"ref":"refs/heads/<new-branch-name>", "sha":"<lost-sha>"}' https://github.bath.ac.uk/api/v3/repos/digital/<repo>/git/refs


    That That will cause github to create a new branch, named with the <new-branch-name>, that you can then pull and massage back into the correct shape.

...