Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

git - Does github remember commit IDs?

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!

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...