Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does github remember commit IDs?

Tags:

git

github

For a few days I was re-writing install.sh file for Scrollback project and since I was the only one working on this and doing it locally, I kept commit ammending the same commit, pushing once in a while to my fork's master. (please ignore best practises here, I was working alone).

In between I remember emailing someone showing my half done work, the URL https://github.com/sindhus/scrollback/blob/8d8f7f414383499c2ab6fec586b4c9665a41c7aa/install.sh

Now by some confusion I lost out on my work locally (think rm -rf), I remember pushing prior to this. So github at some point did see my rebased commit ID of install.sh.

As you can see the above URL lets me access this blob by a commit ID. However I can't access it locally because that same repo was force pushed.

My question how do I get github to show me all commit IDs for a file EVER? All IDs it possibly knows of for that file regardless of path. If I have to use their API I don't mind but I'd like some ideas to dig deep into this.

Thanks!

like image 920
Sindhu S Avatar asked Mar 10 '15 07:03

Sindhu S


2 Answers

My question how do I get github to show me all commit IDs for a file EVER

If you forced push (git push --force) your revised commit once in a while, that commit 8d8f7 has been replaced by a more recent commit with a different SHA.

That means 8d8f7 is now only reference in the reflog of the GitHub repo, which only GitHub support can give you access to.
Cloning the repo would not include 8d8f7 in the local history of that cloned repo.


GitHub "reflog": push events from GitHub Events API

Actually the OP sindhus points out in the comments to "Recovering a commit from Github’s Reflog" by John Engelman:

The GitHub Events API allows to browse through the last events:

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

The "pushEvent" is the one to look for.

Then one can directly create a branch on GitHub in order to make that commit visible again (because not dangling anymore, but reference by an actual object like a branch):

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"ref":"refs/heads/D-commit", "sha":"384f275933d5b762cdb27175aeff1263a8a7b7f7"}' https://api.github.com/repos/<user>/<repo>/git/refs

# JSON request
{
  "ref": "refs/heads/D-commit",
  "sha": "384f275933d5b762cdb27175aeff1263a8a7b7f7"
}

You might need to use a token for the authentication.

like image 163
VonC Avatar answered Sep 19 '22 23:09

VonC


i didn't really get the question so there is some solution:

To see all commit of a specific file: git log --follow filename.

To checkout to old version, find answer here

like image 20
LolWalid Avatar answered Sep 19 '22 23:09

LolWalid