简体   繁体   English

如何在强制推送后下载特定的git树或提交

[英]How to download a specific git tree or commit after force push

I pushed the commit with -force without thinking about the consequences, but I do have all of the previous commits from an old Pull Request and I can still see the files and their commits. 我在没有考虑后果的情况下使用-force推送了提交,但我确实拥有了旧的Pull请求中的所有先前提交,我仍然可以看到文件及其提交。 My question is, is it possible to download the repository even if all of the commits have been reset but there are still commits from an old Pull Request? 我的问题是,是否可以下载存储库,即使所有提交都已重置但仍有来自旧Pull请求的提交?

Say for example I would like to download the repository from this link https://github.com/organizaton/repo.github.io/commits/99fb22467f90a18be7e00aa1d51743bb4af20a43 比如说我想从这个链接下载存储库https://github.com/organizaton/repo.github.io/commits/99fb22467f90a18be7e00aa1d51743bb4af20a43

Is it possible to download the repository files like that? 是否可以下载这样的存储库文件?

The current repository sees only 2 commits, but previously, there was a fair amount of them. 当前的存储库只能看到2个提交,但之前有相当多的提交。 I'm wondering if I can return them back? 我想知道我是否可以归还他们?

Any kind of help is appreciated. 任何形式的帮助表示赞赏。

From inside your local repository you can fetch a github pull request like this: 从本地存储库中,您可以获取这样的github pull请求

git fetch origin pull/ID/head:newbranchname

eg with 1 in place of ID for pull request #1 例如,用1代替拉请求#1ID

After that you can happily switch branch with git checkout newbranchname and inspect your recovered treasure with git log 之后,您可以愉快地使用git checkout newbranchname切换分支,并使用git log检查您恢复的宝藏

Source: https://help.github.com/articles/checking-out-pull-requests-locally/ 资料来源: https//help.github.com/articles/checking-out-pull-requests-locally/

Even if you pushed with force, the remote repository works the same way than your local one, and have received the same objects, which persist for a while. 即使您强行推送,远程存储库的工作方式也与本地存储库相同,并且已经收到相同的对象,这些对象会持续一段时间。

What I would do is to perform a 我要做的是执行一个

git reflog <branch>

… onto the branch you've performed the push --force from, and try to retrieve the hash sum of the last commit in date before you do. ...在您执行push --force的分支上,并尝试在执行之前检索最后一次提交的哈希值。 If you can't find it from here (because you branch would probably have diverged from a long time before you push it), you can try to retrieve the remote reflog through the Github's event API : 如果你从这里找不到它(因为你的分支可能在你推动它之前很长一段时间),你可以尝试通过Github的事件API检索远程reflog:

https://api.github.com/repos/<your account>/<your repository>/events

Once you get this sum, create a tag pointing onto the commit's hash sum 获得此总和后,创建一个指向提交的哈希值的标记

git tag <tagname> <hash>

Then push the lineage onto the server 然后将血统推到服务器上

git push origin <tagname>

Since everything should still already be on server (only unreferenced), this should be immediate. 由于一切都应该已经在服务器上(只是未引用),这应该是立即的。 You'll then be able to browse the old history without altering the current state of your production branches. 然后,您将能够浏览旧历史记录而无需更改生产分支的当前状态。

Docs about Github's API: 关于Github的API的文章:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM