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)#
您只需要執行一次此操作。
設定並配置 github 帳戶
如果您沒有 github 帳戶,請前往 github 頁面並建立一個。
然後您需要配置您的帳戶以允許寫入權限 - 請參閱
產生 SSH 金鑰
關於 github 幫助的說明。接下來,建立您自己的 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
詳細資訊#
Clone 您的 fork#
使用
git clone https://github.com/your-user-name/scipy.git
將您的 fork clone 到本地電腦調查。將目錄變更為您的新 repo:
cd scipy
。然後git branch -a
以顯示所有分支。您會得到類似* main remotes/origin/main
這告訴您目前在
main
分支上,並且您也與origin/main
有remote
連線。什麼遠端儲存庫是remote/origin
?嘗試git remote -v
以查看遠端 URL。它們將指向您的 github fork。現在您想要連線到上游 SciPy github 儲存庫,以便您可以合併來自 trunk 的變更。
將您的儲存庫連結到上游儲存庫#
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 貢獻者指南 以取得更多詳細資訊。