开始使用 Git 开发#
本节和下一节详细描述了如何为使用 SciPy 源代码设置 git。如果你已经设置了 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 副本(fork)#
你只需要做一次。
设置并配置一个 github 账户
如果你没有 github 账户,请前往 github 页面,创建一个。
然后,您需要配置您的账户以允许写访问 - 请参阅 github help 上的
生成 SSH 密钥帮助。接下来,创建你自己的 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/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 贡献者指南 获取更多详情。