Git教程资源
以下Git教程内容均转载自Git 教程_w3cschool和Git 教程 | 菜鸟教程
Git简介
Git 是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。
安装Git
安装包下载地址:https://gitforwindows.org/
Git的基本概念
- 工作区:就是你在电脑里能看到的目录。
- 暂存区:英文叫stage, 或index。一般存放在"git目录"下的index文件(.git/index)中,所以我们把暂存区有时也叫作索引(index)。
- 版本库:工作区有一个隐藏目录.git,这个不算工作区,而是Git的版本库。
下面这个图展示了工作区、版本库中的暂存区和版本库之间的关系:
Git的基础命令
Git分支策略
Git的远程仓库
Github和Gitee
创建平台的Git仓库
RiceQuant 米筐
1. 建立本地仓库
创建项目路径,D:QuantLibProjectsRiceQuant,在路径先下创建仓库
#在项目路径下
$ pwd
/d/QuantLib/Projects/RiceQuant
#创建仓库
$ git init
Initialized empty Git repository in D:/QuantLib/Projects/RiceQuant/.git/
#查看状态
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
2. 编辑提交文件
新建一个文本文件helloworld.py提交
#创建文件
$ touch helloworld.py
$ echo "print('hello wolrd')" > helloworld.py
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
helloworld.py
nothing added to commit but untracked files present (use "git add" to track)
#加入缓存
$ git add helloworld.py
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: helloworld.py
#提交缓存
$ git commit -am 'hello world'
[master (root-commit) 3a9c483] hello world
1 file changed, 1 insertion(+)
create mode 100644 helloworld.py
#最后查看状态
$ git status
On branch master
nothing to commit, working tree clean
3. 连接远程仓库
GitHub
GitHub注册后,新建一个仓库,在用设置里填入SSH密匙。在本地Git中添加远程仓库,推送修改后文件
#添加远程目录
$ git remote add github git@github.com:qt-aaron/RiceQuant.git
$ git remote -v
github git@github.com:qt-aaron/RiceQuant.git (fetch)
github git@github.com:qt-aaron/RiceQuant.git (push)
$ git push -u github master
Everything up-to-date
Branch 'master' set up to track remote branch 'master' from 'github'.
#修改文件
$ echo "#this is a test!" >> helloworld.py
$ git status
On branch master
Your branch is up to date with 'github/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: helloworld.py
no changes added to commit (use "git add" and/or "git commit -a")
#提交文件
$ git commit -am 'a test message.'
warning: LF will be replaced by CRLF in helloworld.py.
The file will have its original line endings in your working directory
[master 8f43d4e] a test message.
1 file changed, 1 insertion(+)
#推送文件
$ git push github
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 269 bytes | 269.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:qt-aaron/RiceQuant.git
3a9c483..8f43d4e master -> master
Gitee
gitee的页面和github极其相似,配置流程基本一致。
配置多个SSH密匙
如果各远程仓库之间用的ssh密匙不一致,需要在~/.ssh文件夹下增加config文件进行配置。
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitee
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github
Uqer 优矿
完全和RiceQuant类似。