如何从 GitHub 项目获取某些提交
我需要从 GitHub 下载 Facebook API。通常,我只需单击“下载”选项卡即可下载最新的源代码。在这种情况下,我需要较旧的提交:91f256424531030a454548693c3a6ca49ca3f35a,但我不知道如何从该提交中获取整个项目...
有人可以告诉我该怎么做吗?
(顺便说一句,我在 Mac 上。不要这样做)知道这是否有什么区别)。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
首先,使用 git 克隆存储库,例如:
下载存储库的完整历史记录,以便您可以切换到任何版本。接下来,更改为新克隆的存储库:
... 并使用 git checkout 更改为正确的提交:
这会给您一个警告,因为您不再位于分支上,并直接切换到特定版本。 (这称为“分离 HEAD”状态。)因为听起来您只想使用此 SDK,而不是主动开发它,所以这不是您需要担心的事情,除非您有兴趣找出答案更多关于 git 如何工作的信息。
First, clone the repository using git, e.g. with:
That downloads the complete history of the repository, so you can switch to any version. Next, change into the newly cloned repository:
... and use
git checkout <COMMIT>
to change to the right commit:That will give you a warning, since you're no longer on a branch, and have switched directly to a particular version. (This is known as "detached HEAD" state.) Since it sounds as if you only want to use this SDK, rather than actively develop it, this isn't something you need to worry about, unless you're interested in finding out more about how git works.
我不知道您发布此问题时它是否存在,但下载提交的最佳且最简单的方法是在查看存储库时单击提交选项卡。然后,不要单击提交名称,而是单击在历史记录中的此时浏览存储库按钮,提交名称右侧带有<>符号/消息,最后点击“克隆”或“下载”按钮时出现的“下载 ZIP”按钮。
我希望它对你们有帮助。
I don't know if it was there when you had posted this question, but the best and easiest way to download a commit is to click on the commits tab when viewing a repository. Then instead of clicking on the commit name, click on Browse the repository at this point in the history button with <> symbol to the right side of the commit name/message, and finally on the Download ZIP button that comes when you click Clone or Download button.
I hope it helps you guys.
Sivan 在 gif 中的回答
1.点击 github 中的 commits
2.选择每个提交右侧的 Browse code
3.点击 download zip ,这将下载该提交时间点的源代码
Sivan's answer in gif
1.Click on commits in github
2.Select Browse code on the right side of each commit
3.Click on download zip , which will download source code at that point of time of commit
要仅使用 7 位 SHA1 简短形式下载提交,请执行以下操作:
工作示例:
说明:
To just download a commit using the 7-digit SHA1 short form do:
Working Example:
Description:
我发现恢复丢失的提交(仅存在于 github 上而不是本地)的最简单方法是创建一个包含此提交的新分支。
git pull
将新分支下拉到本地The easiest way that I found to recover a lost commit (that only exists on github and not locally) is to create a new branch that includes this commit.
git pull
the new branch down to local尝试以下命令序列:
Try the following command sequence:
问题标题不明确。
The question title is ambiguous.
您也可以点击 y 键(Github 帮助, 键盘快捷键)来获取当前修订/提交的“永久链接”。
这会将 URL 从
https://github.com//
(master / HEAD) 更改为https://github.com/ ;/<存储库>/tree/<提交 ID>
.为了下载特定的提交,您需要从该 URL 重新加载页面,因此
克隆或下载
按钮将指向“快照”https://github.com /<用户>/<存储库>/archive/<提交 ID>.zip
而不是最新的
https://github.com///archive/master.zip
。Instead of navigating through the commits, you can also hit the y key (Github Help, Keyboard Shortcuts) to get the "permalink" for the current revision / commit.
This will change the URL from
https://github.com/<user>/<repository>
(master / HEAD) tohttps://github.com/<user>/<repository>/tree/<commit id>
.In order to download the specific commit, you'll need to reload the page from that URL, so the
Clone or Download
button will point to the "snapshot"https://github.com/<user>/<repository>/archive/<commit id>.zip
instead of the latest
https://github.com/<user>/<repository>/archive/master.zip
.如果您想要进行任何特定的提交或想要对任何特定的提交进行编码,那么您可以使用以下命令:
示例:
If you want to go with any certain commit or want to code of any certain commit then you can use below command:
Example:
除了已接受的答案之外:
要查看哈希值,您需要使用建议的命令“git checkout hash”,您可以使用
git log
。然而,根据您的需要,有一种比复制/粘贴哈希更简单的方法。您可以使用 git log --oneline 来以更压缩的格式读取许多提交消息。
假设您看到的是单行提交列表,其中包含最少的信息和仅部分可见的哈希值:
如果您想要
最后一次提交
,您可以使用git checkout master^
。^
为您提供了 master 之前的提交。所以hash222
。如果您想要第n次最后提交,可以使用
git checkout master~n
。例如,使用 git checkout master~2 将为您提供提交 hash333。As addition to the accepted answer:
To see the hashes you need to use the suggested command "git checkout hash", you can use
git log
. Hoewever, depending on what you need, there is an easier way than copy/pasting hashes.You can use
git log --oneline
to read many commit messages in a more compressed format.Lets say you see this a one-line list of the commits with minimal information and only partly visible hashes:
If you want
last commit
, you can usegit checkout master^
. The^
gives you the commit before the master. Sohash222
.If you want the n-th last commit, you can use
git checkout master~n
. For example, usinggit checkout master~2
would give you the commithash333
.要使用 Github 网页来执行此操作,我就是这样做的:转到提交列表 ->点击我需要下载的提交号->点击页面右上角“浏览文件”->单击下拉按钮“代码”,然后单击“下载 ZIP”。
我没有 git 终端,也不想设置一个仅用于下载提交的终端,Sivanand Kheti 的回答帮助我使用网页浏览下载提交,并希望我的步骤可以帮助与我相同的用户。
To use the Github webpage to do this, here's what I did exactly: go to the commit list -> click the commit number I need to download -> click "Browse Files" on the upper-right of the page -> click the dropdown button "Code" and then click "Download ZIP".
I don't have git terminal and don't want to set up one only for downloading a commit, Sivanand Kheti'S answer helped me to download the commit using webpage browsing, and hope my steps help the same users as myself.
写入此内容以查看您的提交
复制您要返回的提交的名称。然后写:
当你这样做时,该提交的文件将被你当前的文件替换。然后你可以对这些做任何你想做的事情,完成后,你可以编写以下命令将当前文件提取到另一个新创建的分支中,这样无论你做什么都不会对你提取的上一个分支有任何危险从
现在开始,您将指定提交的内容放到另一个分支中。
write this to see your commits
copy the name of the commit you want to go back to. then write:
when you do this, the files of that commit will be replaced with your current files. then you can do whatever you want to these and once you're done, you can write the following command to extract the current files into another newly created branch so whatever you make doesn't have any danger for the previous branch that you extracted a commit from
right now, you have the content of a specified commit, into another branch .
git 重置——软
git 重置——硬
**将所有代码重置为特定提交并删除当前未提交的代码
git reset --soft
git reset --hard
**reset all code to particular commit and delete current uncommitted code