github 是否记得提交 ID?
Does github remember commit IDs?
几天来,我一直在为 Scrollback 项目重写 install.sh 文件,因为我是唯一一个在本地做这件事的人,所以我一直在修改同一个提交,一次推送一次而对我叉子的主人。 (请忽略这里的最佳实践,我是一个人工作)。
在这期间,我记得曾通过电子邮件向某人展示我完成了一半的工作,URL https://github.com/sindhus/scrollback/blob/8d8f7f414383499c2ab6fec586b4c9665a41c7aa/install.sh
现在由于一些困惑,我在本地丢失了我的工作(想想 rm -rf),我记得在此之前推动。所以 github 在某些时候确实看到了我重新设置的 install.sh.
的提交 ID
如您所见,URL 让我可以通过提交 ID 访问此 blob。
但是我无法在本地访问它,因为同一个回购被强制推送。
我的问题是如何让 github 显示文件的所有提交 ID?无论路径如何,它可能知道的该文件的所有 ID。如果我必须使用他们的 API 我不介意,但我想要一些想法来深入研究它。
谢谢!
在本地克隆您的存储库,然后在您的文件上尝试此操作:
git log --follow install.sh
它应该会显示您可以在 github 上使用的 ID。
My question how do I get github to show me all commit IDs for a file EVER
如果您偶尔强制推送 (git push --force
) 修改后的提交,则该提交 8d8f7 已被替换为 。
这意味着 8d8f7 现在仅在 GitHub 存储库的 reflog 中引用,只有 GitHub 支持才能让您访问 .
克隆存储库不会在该克隆存储库的本地历史记录中包含 8d8f7。
GitHub "reflog": 从 GitHub 事件推送事件 API
实际上 OP sindhus points out to "Recovering a commit from Github’s Reflog" by John Engelman:
GitHub Events API 允许浏览最近的事件:
curl https://api.github.com/repos/<user>/<repo>/events
"pushEvent" 就是要找的人。
然后可以直接在 GitHub 上创建一个分支,以使该提交再次可见(因为不再悬空,而是被像分支这样的实际对象引用):
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"
}
你可能 .
我没有真正理解问题所以有一些解决方案:
查看特定文件的所有提交:
git log --follow filename
.
要结帐到旧版本,找到答案 here
我不确定是否有一种方法可以跨修改后的提交获取文件的所有版本。但是,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 日志 --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
但总的来说,即使您是唯一的开发人员,不断修改的 "process" 也是不好的。修复上次提交的错误是一次性的事情。
几天来,我一直在为 Scrollback 项目重写 install.sh 文件,因为我是唯一一个在本地做这件事的人,所以我一直在修改同一个提交,一次推送一次而对我叉子的主人。 (请忽略这里的最佳实践,我是一个人工作)。
在这期间,我记得曾通过电子邮件向某人展示我完成了一半的工作,URL https://github.com/sindhus/scrollback/blob/8d8f7f414383499c2ab6fec586b4c9665a41c7aa/install.sh
现在由于一些困惑,我在本地丢失了我的工作(想想 rm -rf),我记得在此之前推动。所以 github 在某些时候确实看到了我重新设置的 install.sh.
的提交 ID如您所见,URL 让我可以通过提交 ID 访问此 blob。 但是我无法在本地访问它,因为同一个回购被强制推送。
我的问题是如何让 github 显示文件的所有提交 ID?无论路径如何,它可能知道的该文件的所有 ID。如果我必须使用他们的 API 我不介意,但我想要一些想法来深入研究它。
谢谢!
在本地克隆您的存储库,然后在您的文件上尝试此操作:
git log --follow install.sh
它应该会显示您可以在 github 上使用的 ID。
My question how do I get github to show me all commit IDs for a file EVER
如果您偶尔强制推送 (git push --force
) 修改后的提交,则该提交 8d8f7 已被替换为
这意味着 8d8f7 现在仅在 GitHub 存储库的 reflog 中引用,只有 GitHub 支持才能让您访问 .
克隆存储库不会在该克隆存储库的本地历史记录中包含 8d8f7。
GitHub "reflog": 从 GitHub 事件推送事件 API
实际上 OP sindhus points out
GitHub Events API 允许浏览最近的事件:
curl https://api.github.com/repos/<user>/<repo>/events
"pushEvent" 就是要找的人。
然后可以直接在 GitHub 上创建一个分支,以使该提交再次可见(因为不再悬空,而是被像分支这样的实际对象引用):
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"
}
你可能
我没有真正理解问题所以有一些解决方案:
查看特定文件的所有提交:
git log --follow filename
.
要结帐到旧版本,找到答案 here
我不确定是否有一种方法可以跨修改后的提交获取文件的所有版本。但是,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 日志 --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
但总的来说,即使您是唯一的开发人员,不断修改的 "process" 也是不好的。修复上次提交的错误是一次性的事情。