使用 Git 进行开发入门#
本节和下一节详细介绍如何设置 Git 以便与 SciPy 源代码一起使用。如果您已经设置了 Git,请跳至 开发工作流程.
基本 Git 设置#
使用 Git 进行开发完全可以在没有 GitHub 的情况下完成。Git 是一个分布式版本控制系统。为了在您的机器上使用 Git,您必须首先 安装 Git.
向 Git 自我介绍
git config --global user.email you@yourdomain.example.com git config --global user.name "Your Name Comes Here"
创建您自己的 SciPy 副本(分支)#
您只需要执行一次此操作。
设置和配置 github 帐户
如果您没有 github 帐户,请访问 github 页面并创建一个。
然后,您需要配置您的帐户以允许写入访问 - 请参阅 github 帮助 上的
Generating SSH keys
帮助。接下来,创建您自己的 SciPy 的分支副本.
概述#
git clone https://github.com/your-user-name/scipy.git
cd scipy
git remote add upstream https://github.com/scipy/scipy.git
git submodule update --init
详细说明#
克隆您的分支#
使用
git clone https://github.com/your-user-name/scipy.git
将您的分支克隆到本地计算机调查。将目录更改为您的新仓库:
cd scipy
。然后使用git branch -a
显示所有分支。您将看到类似以下内容:* main remotes/origin/main
这表示您当前位于
main
分支,并且您还与origin/main
建立了remote
连接。remote/origin
是哪个远程仓库?尝试使用git remote -v
查看远程仓库的 URL。它们将指向您的 github 分支。现在,您需要连接到上游 SciPy github 仓库,以便您可以合并主干中的更改。
将您的仓库链接到上游仓库#
cd scipy
git remote add upstream https://github.com/scipy/scipy.git
upstream
只是我们用来指代 SciPy 在 SciPy github 上的主仓库的任意名称。
为了确认,您可以使用 git remote -v show
查看您现在是否拥有一个新的“远程仓库”,您将看到类似以下内容:
upstream https://github.com/scipy/scipy.git (fetch)
upstream https://github.com/scipy/scipy.git (push)
origin https://github.com/your-user-name/scipy.git (fetch)
origin https://github.com/your-user-name/scipy.git (push)
为了与 SciPy 中的更改保持同步,您需要设置您的仓库,使其默认从 upstream
拉取。可以使用以下命令完成此操作:
git config branch.main.remote upstream
git config branch.main.merge refs/heads/main
您的配置文件现在应该类似于以下内容(来自 $ cat .git/config
):
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = false
[remote "origin"]
url = https://github.com/your-user-name/scipy.git
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "upstream"]
url = https://github.com/scipy/scipy.git
fetch = +refs/heads/*:refs/remotes/upstream/*
[branch "main"]
remote = upstream
merge = refs/heads/main
更新子模块#
初始化 git 子模块
git submodule update --init
这将获取并更新 SciPy 所需的任何子模块(例如 Boost)。
下一步#
您现在可以开始使用 SciPy 进行开发。查看 SciPy 贡献者指南 获取更多详细信息。