# GIT
Git 全局設置
```
git config --global user.name "李吉"
git config --global user.email "81020302@qq.com"
```
#### 版本回退
```
回到過去 回到未來
$ git reset --hard commit_id // commit_id就是要回退的版本
$ git log // 可以查看提交歷史,以便確定要回退到哪個版本
$ git reflog // 查看命令歷史,以便確定要的哪個版本
```
#### 公鑰生成
```
// 生成 sshkey
ssh-keygen -t rsa -C "xxxxx@xxxxx.com"
// 查看公鑰 復制生成后的 ssh key即可添加
cat ~/.ssh/id_rsa.pub
// 如果是 碼云,以下命令,輸入后,再輸入yes,即可加入信任列表
ssh -T git@gitee.com
```
#### Git標簽
```
// 查看標簽列表
git tag
// 打標簽
git tag -a v4.0.5 -m "version 4.0.5"
// 推送
git push origin master --tags
// 刪除遠程標簽
git push origin master :refs/tags/v4.0.5
// 刪除本地標簽
git tag -d v0.8
```
#### 暫存區
```
git stash list // 列出所有
git stash drop stash@{0} 這是刪除第一個隊列
git stash clear // 清理所有
```
#### 分支
~~~
# 拉取遠程分支到本地
$ git checkout -b 本地分支名 origin/遠程分支名
# 列出所有本地分支
$ git branch
# 列出所有遠程分支
$ git branch -r
# 列出所有本地分支和遠程分支
$ git branch -a
# 新建一個分支,但依然停留在當前分支
$ git branch [branch-name]
# 新建一個分支,并切換到該分支
$ git checkout -b [branch]
# 新建一個分支,指向指定commit
$ git branch [branch] [commit]
# 新建一個分支,與指定的遠程分支建立追蹤關系
$ git branch --track [branch] [remote-branch]
# 切換到指定分支,并更新工作區
$ git checkout [branch-name]
# 切換到上一個分支
$ git checkout -
# 建立追蹤關系,在現有分支與指定的遠程分支之間
$ git branch --set-upstream [branch] [remote-branch]
# 合并指定分支到當前分支
$ git merge [branch]
# 選擇一個commit,合并進當前分支
$ git cherry-pick [commit]
# 刪除分支
$ git branch -d [branch-name]
# 刪除遠程分支
$ git push origin --delete [branch-name]
$ git branch -dr [remote/branch]
~~~