Git 使用手册独家实战
0、查看本机公钥
JackFeng@JackFeng MINGW64 ~/Desktop
$ cd ~/.ssh
JackFeng@JackFeng MINGW64 ~/.ssh
$ ls
config id_rsa id_rsa.pub id_rsa_sql id_rsa_sql.pub known_hosts
JackFeng@JackFeng MINGW64 ~/.ssh
$ cat id_rsa.pub
1、配置多个git仓库
多仓库之间 'ssh-key切换'
#1、生成客户端自己的密钥对
ssh-keygen ---- 一顿回车即可
# 实际操作 换成你的邮箱即可
ssh-keygen -t rsa -C "[email protected]"
可以在客户端的家目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥。
生成新的ssh-key
#[email protected] 工作邮箱地址
ssh-keygen -t rsa -C '[email protected]' -f id_rsa_second
配置多个仓库
config
# 配置github.com
Host github.com
HostName github.com
IdentityFile ~\.ssh\id_rsa
PreferredAuthentications publickey
User yinjie.feng
# 配置SQLSQ
Host SQL
HostName github.com
IdentityFile ~\.ssh\id_rsa_sql
PreferredAuthentications publickey
User yinjie.feng
测试是否调通
JackFeng@JackFeng MINGW64 ~/.ssh
$ vim config
JackFeng@JackFeng MINGW64 ~/.ssh
$ ssh -T [email protected]
Hi A2Data! You've successfully authenticated, but GitHub does not provide shell access.
JackFeng@JackFeng MINGW64 ~/.ssh
$ vim config
JackFeng@JackFeng MINGW64 ~/.ssh
$ ssh -T git@SQL
Hi MineData-SQL! You've successfully authenticated, but GitHub does not provide shell access.
2、从远程项目拉取
git clone 项目地址
3、提交代码到远程仓库
常规操作
##添加
git add . .
#查看状态
git status
# 提交
git commit -m "代码描述"
# 再次查看状态
git status
# 拉取最新代码
git pull
# 提交
git push
4、git分支操作
Git初始化
git init
git clone --- 克隆项目
JackFeng@JackFeng MINGW64 /d/Practice
$ git clone [email protected]:MineData-SQL/SQL.git
Cloning into 'SQL'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
创建分支
git branch <branch_name> #指定分支名称
git checkout -b ["分支名"]
查看分支
git branch # 查看所有分支,* 号所属代表当前分支
git branch # 查看分支详情,包括分支指向得commitid及提交信息
切换分支
git checkout <branch_name> #切换到指定分支
git checkout -b <branch_name> #创建并切换到指定分支
删除分支
git branch -d <branch_name>
.#删除一个干净的分支(即相对当前分支而言该分支没有新的提交记录)
git branch -D <branch_name>
.#强制删除一个分支,该分支有没有合并到当前分支的提交记录
注意:删除分支前都需要先切换到其他分支才能进行删除操作
分支恢复
git reflog
git branch <branch_name> <hash_val>
#根据指定commit创建新分支
分支改名
git branch -m <branch_name> newname
JackFeng@JackFeng MINGW64 /d/Practice/SQL (master-two)
$ git branch -m master-one master-O
JackFeng@JackFeng MINGW64 /d/Practice/SQL (master-two)
$ git branch
master
master-O
* master-two
分支合并
分支合并细节
JackFeng@JackFeng MINGW64 /d/Practice/SQL (master)
$ git checkout master-two
Switched to branch 'master-two'
JackFeng@JackFeng MINGW64 /d/Practice/SQL (master-two)
$ echo " thank you for attention DataScience " >> a2data.txt
JackFeng@JackFeng MINGW64 /d/Practice/SQL (master-two)
$ git add a2data.txt
warning: LF will be replaced by CRLF in a2data.txt.
The file will have its original line endings in your working directory
JackFeng@JackFeng MINGW64 /d/Practice/SQL (master-two)
$ git commit -m " add file"
[master-two 59a8816] add file
1 file changed, 1 insertion(+)
create mode 100644 a2data.txt
JackFeng@JackFeng MINGW64 /d/Practice/SQL (master-two)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
JackFeng@JackFeng MINGW64 /d/Practice/SQL (master)
$ git merge --ff -m "meger master-two branch" master-two
Updating ab83ffb..59a8816
Fast-forward (no commit created; -m option ignored)
a2data.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 a2data.txt
JackFeng@JackFeng MINGW64 /d/Practice/SQL (master)
$ git log --pretty=oneline -1
59a88161e630f0853b852946fddb6c7e787906fe (HEAD -> master, master-two) add file
冲突解决
master
master-O
合并分支