6500 万开发人员和 300 万组织不会错。GitHub拥有超过 2 亿个代码存储库,是全球个人编码人员(coders)和公司的首选开发平台。开发人员(Developers)使用GitHub来构建、维护甚至分发他们的软件,因此像您这样的用户可以直接从GitHub下载文件和查看代码。
GitHub可以轻松下载和查看应用程序的源代码。本指南将向您展示如何直接从GitHub的网站下载文件,以便您自己查看项目的代码。
安装代码查看器
在下载任何代码之前,您需要安装一个能够查看该代码的程序。Visual Studio Code是一款免费、开源且经过简化的代码编辑器,允许用户查看和调试代码以及运行任务。
按照安装向导下载并安装Visual Studio Code。然后,您就可以查看可以从GitHub下载的文件和代码了。
有许多不同的代码编辑器。如果项目是使用不同的IDE(集成开发环境)创建的,那么Visual Studio可能不适合编辑该代码。话(Having)虽如此,Visual Studio Code将允许您编辑(Code)GitHub 上(GitHub)大多数项目的代码,如果您只想查看(view )代码,它将始终有效。
在GitHub 上(GitHub)下载项目的最新版本(Most Recent Release)
假设您是一名程序员(programmer),想要下载开源(open-source)软件的项目文件。在GitHub 上(GitHub),项目文件发布在存储库中,每个项目都有一个存储库主页。您无需在GitHub 上(GitHub)拥有用户帐户即可查看或下载文件。
按照以下步骤下载您感兴趣的项目的最新版本。
- 去github.com。
- 在 GitHub 的搜索框中按名称搜索项目。
- 导航到存储库的主页。
- 找到版本(Releases)部分并选择最新版本。在 GitHub 的桌面站点上,发布位于右侧的侧边栏中。或者,您可以将/releases添加到存储库URL。顶部的版本将是最新的。
- 接下来,找到并展开资产(Assets )部分。
- 由于要查看代码,请下载源代码.zip文件。Linux用户应下载源代码 tar.gz 文件。
- 提取您在步骤 6 中下载的源代码存档。
- 切换到可视代码编辑器(Visual Code Editor)并选择File > Open Folder。导航(Navigate)并选择您在步骤 7 中提取的文件夹。
- 按选择文件夹(Select Folder )按钮。
- 在Visual Studio Code中,您将看到左侧列出的项目。您可以展开下拉箭头以查看项目中包含的所有文件。
- 在左侧面板中选择一个项目文件,代码将出现在右侧的工作区中。
上述步骤将引导您了解如何查看GitHub 上(GitHub)项目的最新版本中的文件。但是,如果您想查看来自项目特定分支的文件怎么办?
从特定分支下载
在GitHub中,一个存储库可以有多个分支(branches)。每个分支都有一个唯一的名称,并由一组代码更改组成。它是特定时间点代码特定部分的副本,您可以在其中进行更改而不会破坏原始代码。代码(Code)更改在分支内进行,然后,如果请求和批准,可以合并回项目的主要工作版本,称为主分支(master branch)。
假设您想从GitHub 上(GitHub)项目的特定分支下载和查看文件。为此,请按照下列步骤操作:
- 按名称搜索项目并导航到项目的存储库主页。
- 找到分支(branch)下拉列表,然后选择要下载的分支。通常,Master分支包含最新的代码,但并非总是如此。
- 现在您已经选择了所需的分支,找到并选择绿色的Code按钮,选择Download Zip或者,如果您看到选项,则选择Open with Visual Studio。(您可能还会看到使用 GitHub Desktop 打开(Open with GitHub Desktop)的选项。)
- 按照上一节中的步骤 7-11提取 zip 文件并从Visual Studio Code中打开提取的文件夹。(Visual Studio Code)
按照上述步骤,您可以在GitHub 上(GitHub)查看项目特定分支的代码。接下来(Next),我们将讨论如何深入挖掘并从特定提交(commit)下载文件。
从特定提交下载
每次将代码更改应用于存储库时,都会通过commit添加。提交包含自上次代码更新以来的所有更改。如果您尝试调试由最近的代码更改引起的问题,您可能希望从特定提交下载。
- 导航到存储库主页并选择要使用的分支。通常,这将是主分支。
- 找到并选择提交(Commits )链接。
- 通过选择提交的标题来选择要下载的提交。
- 现在您在您选择的提交的页面上。接下来,选择浏览文件(Browse files)按钮。
- 找到并选择绿色的代码(Code)按钮,然后选择下载 zip(Download zip)或(如果可用)使用 Visual Studio 打开(Open with Visual Studio)。
- 最后,解压缩 zip 文件并在 Visual Studio Code中打开解压缩的文件夹。
GitHub 还有更多
从GitHub(GitHub)下载和查看项目文件只是冰山一角。最终,您可能想要分叉一个存储库,将其克隆到本地存储库,提交更改,将更改推送回您的分叉,然后提交拉取请求,要求项目所有者将您的更改合并到源存储库中。
How to Download Files and View Code from GitHub
Sixty-five million developers and three million organizations can’t be wrong. Hosting over 200 million code repositories, GitHub is the develоpment platform of choice for individual coders and companies across the globe. Developers use GitHub to build, maintain, and even distribute their software so users like you can download files and view code straight from GitHub.
GitHub makes it easy to download and view an app’s source code. This guide will show you how to directly download files from GitHub’s website so you can view a project’s code yourself.
Install a Code Viewer
Before you download any code, you’ll need to install a program capable of viewing that code. Visual Studio Code is a free, open source, and streamlined code editor that allows users to view and debug code and run tasks.
Download and install Visual Studio Code by following the installation wizard. Then you’ll be ready to view files and code that you can download from GitHub.
There are many different code editors. If a project was created with a different IDE (integrated development environment), then Visual Studio might not be ideal for editing that code. Having said that, Visual Studio Code will allow you to edit the code of most of the projects on GitHub, and it will always work if all you want to do is view the code.
Downloading the Most Recent Release of a Project on GitHub
Let’s say you’re a programmer who wants to download the project files for an open-source piece of software. On GitHub, project files are posted in repositories, and each project has a repository home page. You don’t need to have a user account on GitHub to view or download files.
Follow these steps to download the most recent release of the project you’re interested in.
- Go to github.com.
- Search for the project by name in GitHub’s search box.
- Navigate to the home page for the repository.
- Find the Releases section and select the latest version. On GitHub’s desktop site, Releases are in the sidebar on the right. Alternatively, you can add /releases to the repository URL. The release at the top will be the most recent.
- Next, find and expand the Assets section.
- Since you want to view the code, download the source code .zip file. Linux users should download the source code tar.gz file.
- Extract the source code archive you downloaded in step 6.
- Switch to Visual Code Editor and select File > Open Folder. Navigate and select the folder you extracted in step 7.
- Press the Select Folder button.
- In Visual Studio Code, you’ll see the project listed on the left. You can expand the dropdown arrows to see all the files included in the project.
- Select a project file in the panel on the left, and the code will appear in the workspace on the right.
The steps above walk you through how to view the files from the most recent release of a project on GitHub. But what if you want to view files from a specific branch of the project?
Downloading From a Specific Branch
In GitHub, a repository can have multiple branches. Every branch has a unique name, and consists of a set of code changes. It’s a copy of a particular part of the code at a particular point in time where you can make changes without destroying the original. Code changes are made inside branches and then, if requested and approved, can be merged back into the main working version of the project called the master branch.
Let’s imagine that you want to download and view files from a specific branch of a project on GitHub. To do so, follow these steps:
- Search for the project by name and navigate to the project’s repository home page.
- Find the branch dropdown, and select the branch you want to download. Typically, the Master branch contains the most recent code, but not always.
- Now that you have selected the branch you want, find and select the green Code button, choosing either Download Zip or, if you see the option, Open with Visual Studio. (You may also see an option to Open with GitHub Desktop.)
- Extract the zip file and open the extracted folder from within Visual Studio Code by following steps 7-11 in the section above.
By following the steps above, you can view the code from a specific branch of a project on GitHub. Next, we’ll discuss how to drill down even farther and download files from a specific commit.
Downloading From a Specific Commit
Every time a code change is applied to a repository, it is added via a commit. The commit contains all of the changes since the last code update. You may want to download from a specific commit if you’re trying to debug issues that were caused by a recent code change.
- Navigate to the repository home page and select the branch you want to work with. Normally, this will be the master branch.
- Find and select the Commits link.
- Choose the commit you want to download by selecting the title of the commit.
- Now you’re on the page for the commit you selected. Next, select the Browse files button.
- Find and select the green Code button, and choose either Download zip or, if it’s available, Open with Visual Studio.
- Finally, extract the zip file and open the extracted folder in Visual Studio Code.
There’s So Much More to GitHub
Downloading and viewing project files from GitHub is just the tip of the iceberg. Eventually, you may want to fork a repository, clone it to a local repository, commit changes, push changes back to your fork, and then submit a pull request asking the project owner to merge your changes into the source repository.