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 副本(Fork)#

您只需要做一次。

  1. 设置并配置一个 github 帐户

    如果您没有 github 帐户,请前往 github 页面创建一个。

    然后您需要配置您的帐户以允许写入访问 - 请参阅 生成 SSH 密钥github 帮助上的帮助。

  2. 接下来,创建您自己的 SciPy 的 Fork 副本

概述#

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

详细信息#

克隆您的 Fork#

  1. 使用 git clone https://github.com/your-user-name/scipy.git 将您的 Fork 克隆到本地计算机

  2. 调查。将目录更改为您新的 repo:cd scipy。然后 git branch -a 以显示所有分支。您会得到类似以下内容

    * main
    remotes/origin/main
    

    这告诉您,您当前在 main 分支上,并且您还具有到 origin/mainremote 连接。什么远程仓库是 remote/origin?尝试 git remote -v 查看远程仓库的 URL。它们将指向您的 github Fork。

    现在您要连接到上游 SciPy github 仓库,以便您可以从主干合并更改。

将您的仓库链接到上游仓库#

cd scipy
git remote add upstream https://github.com/scipy/scipy.git

upstream 这里只是我们用来指代在 SciPy github 上的主 SciPy 仓库的任意名称。

仅仅是为了您自己的满意,通过 git remote -v show 向自己展示您现在有一个新的“remote”,给您类似以下内容

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 贡献者指南以获取更多详细信息。