github是否记得提交ID?

几天后,我正在为ScrollBack项目重新编写install.sh文件,由于我是唯一一个在本地执行此操作的人,所以我一直在提交相同的提交,并且偶尔推送给我的fork主。 (请忽略最佳做法,我一个人工作)。

在我记得之间发送电子邮件给我显示我的一半完成的工作,URL https://github.com/sindhus/scrollback/blob/8d8f7f414383499c2ab6fec586b4c9665a41c7aa/install.sh

现在由于一些困惑,我在本地工作中失去了工作(想想rm -rf),我记得在这之前推动。 所以github在某些时候看到了我的rebased提交ID为install.sh。

正如你可以看到上面的URL让我通过提交ID来访问这个blob。 不过,我不能在本地访问它,因为同一个回购是强制推动。

我的问题如何让github向我展示所有提交文件EVER的ID? 无论path如何,它可能知道该文件的所有ID。 如果我不得不使用他们的API,我不介意,但我想一些想法深入挖掘。

谢谢!

我的问题如何让github向我展示所有提交文件EVER的ID

如果你偶尔强制推送( git push --force )你的修改的提交,那么这个提交8d8f7已经被一个不同的SHA提交了 。

这意味着8d8f7现在只能在GitHub仓库的reflog中引用 只有GitHub的支持可以让你访问
克隆回购将不包括8d8f7在该克隆回购的当地历史。


GitHub“reflog”:从GitHub Events API推送事件

实际上, OP sindhus 在 John Engelman 的 “ 从Github的Reflog中恢复提交 ” 的评论中指出:

GitHub Events API允许浏览最近的事件:

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

“pushEvent”是一个寻找。

然后,可以直接在GitHub上创build一个分支,以便使该提交再次可见(因为不再是悬挂,而是通过像分支一样的实际对象引用):

 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" } 

您可能需要使用令牌进行身份validation 。

我没有真正的问题,所以有一些解决scheme:

要查看特定文件的所有提交: git log --follow filename

结帐到旧版本,在这里find答案

克隆你的回购本地,然后在你的文件上试试这个:

 git log --follow install.sh 

它应该显示你可以在github上使用的ID。

我不确定是否有一种方法可以通过修改提交获取文件的所有版本。 但是,reflog将包含更早的信息,您可以手动提取它们。 一个例子如下。

这是我第一次提交

 echo "a" > a.txt && git add a.txt && git commit -m "Version 0" 

之后,又多了一些修改。

 % echo "aa" > a.txt && git add a.txt && git commit --amend -m "Version 1" % echo "aaa" > a.txt && git add a.txt && git commit --amend -m "Version 2" % echo "aaaa" > a.txt && git add a.txt && git commit --amend -m "Version 3" % echo "aaaaa" > a.txt && git add a.txt && git commit --amend -m "Version 4" 

而我的日志只是一个条目

%git log –oneline a8d6c39版本4

我的reflog拥有一切

 % git reflog master a8d6c39 master@{0}: commit (amend): Version 4 cf87b8f master@{1}: commit (amend): Version 3 c45a91e master@{2}: commit (amend): Version 2 63c7f5a master@{3}: commit (amend): Version 1 f2b3336 master@{4}: commit (initial): Version 0 

所以,如果你想看看你的文件在版本4,版本3等,你可以做到这一点

 % git show a8d6c39:a.txt aaaaa % git show cf87b8f:a.txt aaaa % git show c45a91e:a.txt aaa % git show 63c7f5a:a.txt aa % git show f2b3336:a.txt a 

一般来说,即使你是唯一的开发者,连续修改的“过程”也是不好的。 这是一个你应该做的一件事,以解决上次提交的错误。