如何从 GitHub 项目获取某些提交

发布于 2024-12-11 03:00:55 字数 406 浏览 0 评论 0 原文

我需要从 GitHub 下载 Facebook API。通常,我只需单击“下载”选项卡即可下载最新的源代码。在这种情况下,我需要较旧的提交:91f256424531030a454548693c3a6ca49ca3f35a,但我不知道如何从该提交中获取整个项目...

有人可以告诉我该怎么做吗?

(顺便说一句,我在 Mac 上。不要这样做)知道这是否有什么区别)。

I need to download the Facebook API from GitHub. Normally, I just click on the 'Downloads" tab to download the latest source code. In this case, I need an older commit: 91f256424531030a454548693c3a6ca49ca3f35a, but I have no idea how to get the entire project from that commit...

Can someone please tell me how to do this?

(BTW, im on a mac. Don't know if that makes any difference).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

剩一世无双 2024-12-18 03:00:55

首先,使用 git 克隆存储库,例如:

git clone git://github.com/facebook/facebook-ios-sdk.git

下载存储库的完整历史记录,以便您可以切换到任何版本。接下来,更改为新克隆的存储库:

cd facebook-ios-sdk

... 并使用 git checkout 更改为正确的提交:

git checkout 91f25642453

这会给您一个警告,因为您不再位于分支上,并直接切换到特定版本。 (这称为“分离 HEAD”状态。)因为听起来您只想使用此 SDK,而不是主动开发它,所以这不是您需要担心的事情,除非您有兴趣找出答案更多关于 git 如何工作的信息。

First, clone the repository using git, e.g. with:

git clone git://github.com/facebook/facebook-ios-sdk.git

That downloads the complete history of the repository, so you can switch to any version. Next, change into the newly cloned repository:

cd facebook-ios-sdk

... and use git checkout <COMMIT> to change to the right commit:

git checkout 91f25642453

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.

浅听莫相离 2024-12-18 03:00:55

我不知道您发布此问题时它是否存在,但下载提交的最佳且最简单的方法是在查看存储库时单击提交选项卡。然后,不要单击提交名称,而是单击在历史记录中的此时浏览存储库按钮,提交名称右侧带有<>符号/消息,最后点击“克隆”或“下载”按钮时出现的“下载 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.

冰雪梦之恋 2024-12-18 03:00:55

Sivan 在 gif 中的回答在此处输入图像描述

1.点击 github 中的 commits

2.选择每个提交右侧的 Browse code

3.点击 download zip ,这将下载该提交时间点的源代码

Sivan's answer in gif enter image description here

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

苏璃陌 2024-12-18 03:00:55

要仅使用 7 位 SHA1 简短形式下载提交,请执行以下操作:

工作示例:

https://github.com/python/cpython/archive/31af650.zip  

说明:

 `https://github.com/username/projectname/archive/commitshakey.zip`

如果您有长哈希密钥 31af650ee25f65794b75d4dfefed6fe4758781c1,只需获取前 7 个字符 31af650。这是 GitHub 的默认设置。

To just download a commit using the 7-digit SHA1 short form do:

Working Example:

https://github.com/python/cpython/archive/31af650.zip  

Description:

 `https://github.com/username/projectname/archive/commitshakey.zip`

If you have the long hash key 31af650ee25f65794b75d4dfefed6fe4758781c1, just get the first 7 chars 31af650. It's the default for GitHub.

拥有 2024-12-18 03:00:55

我发现恢复丢失的提交(仅存在于 github 上而不是本地)的最简单方法是创建一个包含此提交的新分支。

  1. 打开提交(网址如:github.com/org/repo/commit/long-commit-sha)
  2. 单击右上角的“浏览文件”
  3. 单击左上角的下拉列表“树:short-sha...”
  4. 输入新分支名称
  5. 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.

  1. Have the commit open (url like: github.com/org/repo/commit/long-commit-sha)
  2. Click "Browse Files" on the top right
  3. Click the dropdown "Tree: short-sha..." on the top left
  4. Type in a new branch name
  5. git pull the new branch down to local
橙味迷妹 2024-12-18 03:00:55

尝试以下命令序列:

$ git fetch origin <copy/past commit sha1 here>
$ git checkout FETCH_HEAD
$ git push origin master

Try the following command sequence:

$ git fetch origin <copy/past commit sha1 here>
$ git checkout FETCH_HEAD
$ git push origin master
恍梦境° 2024-12-18 03:00:55

问题标题不明确。

The question title is ambiguous.

有木有妳兜一样 2024-12-18 03:00:55

您也可以点击 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) to https://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.

々眼睛长脚气 2024-12-18 03:00:55

如果您想要进行任何特定的提交或想要对任何特定的提交进行编码,那么您可以使用以下命令:

git checkout <BRANCH_NAME>
git reset --hard  <commit ID which code you want>
git push --force

示例:

 git reset --hard fbee9dd 
 git push --force

If you want to go with any certain commit or want to code of any certain commit then you can use below command:

git checkout <BRANCH_NAME>
git reset --hard  <commit ID which code you want>
git push --force

Example:

 git reset --hard fbee9dd 
 git push --force
迟到的我 2024-12-18 03:00:55

除了已接受的答案之外:

要查看哈希值,您需要使用建议的命令“git checkout hash”,您可以使用 git log。然而,根据您的需要,有一种比复制/粘贴哈希更简单的方法。

您可以使用 git log --oneline 来以更压缩的格式读取许多提交消息。

假设您看到的是单行提交列表,其中包含最少的信息和仅部分可见的哈希值:

hash111 (HEAD -> master, origin/master, origin/HEAD)
hash222 last commit
hash333 I want this one
hash444 did something
....

如果您想要最后一次提交,您可以使用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:

hash111 (HEAD -> master, origin/master, origin/HEAD)
hash222 last commit
hash333 I want this one
hash444 did something
....

If you want last commit, you can use git checkout master^. The ^ gives you the commit before the master. So hash222.

If you want the n-th last commit, you can use git checkout master~n. For example, using git checkout master~2would give you the commit hash333.

菩提树下叶撕阳。 2024-12-18 03:00:55

要使用 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.

青巷忧颜 2024-12-18 03:00:55

写入此内容以查看您的提交

git log --oneline

复制您要返回的提交的名称。然后写:

git checkout "name of the commit"

当你这样做时,该提交的文件将被你当前的文件替换。然后你可以对这些做任何你想做的事情,完成后,你可以编写以下命令将当前文件提取到另一个新创建的分支中,这样无论你做什么都不会对你提取的上一个分支有任何危险从

git checkout -b "name of a branch to extract the files to"

现在开始,您将指定提交的内容放到另一个分支中。

write this to see your commits

git log --oneline

copy the name of the commit you want to go back to. then write:

git checkout "name of the commit"

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

git checkout -b "name of a branch to extract the files to"

right now, you have the content of a specified commit, into another branch .

青衫负雪 2024-12-18 03:00:55

git 重置——软

git 重置——硬
**将所有代码重置为特定提交并删除当前未提交的代码

git reset --soft

git reset --hard
**reset all code to particular commit and delete current uncommitted code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文