命令
PS:
以下<file>均可替換為 . / * / <file> <file>
初始化及配置
// 初始化
$ git init
// 設(shè)置用戶名
$ git config --global user.name <user.name>
// 設(shè)置郵箱
$ git config --global user.email <user.email>
// 設(shè)置默認(rèn)編輯器
$ git config --global core.editor <core.editor>
$ git config --global core.editor notepad
文件 / 目錄基本操作
// 新建文件夾
$ mkdir <file>
// 打開文件夾
$ cd <file>
$ cd ..
// 展示當(dāng)前目錄路徑
$ pwd
// 查看目錄下文件
$ ls
// 查看目錄下文件(含隱藏文件)
$ ls -a
工作區(qū)管理
// 撤銷工作區(qū)修改
$ git checkout -- <file>
// 撤銷暫存區(qū)修改
$ git reset HEAD <file>
// 將文件從工作區(qū)添加到暫存區(qū)
$ git add <file>
// 將文件從暫存區(qū)提交到倉庫
$ git commit <file>
$ git commit -m <text>
// 查看狀態(tài)
$ git status
// 查看修改
$ git diff
// 從版本庫刪除文件
$ rm <file>
$ git rm <file>
工作區(qū)版本管理
// 查看提交歷史
$ git log
// 回退到某一個版本
$ git reset --hard <commitID>
// 查看命令歷史
$ git reflog
// 查看工作區(qū)和版本庫里面最新版本的區(qū)別
$ git diff HEAD -- <file>
工作區(qū)分支管理
// 查看分支
$ git branch
// 新建分支
$ git branch <branch>
// 切換分支
$ git checkout <branch>
// 新建分支并切換到新分支
$ git checkout -b <branch>
// 刪除分支
$ git branch -d <branch>
$ git branch -D <branch>
// 合并分支到當(dāng)前分支,合并遇到?jīng)_突時需要解決沖突,再重新提交
$ git merge <branch>
$ git merge --no-ff -m <text> <branch>
工作現(xiàn)場
// 保存工作現(xiàn)場
$ git stash
// 查看工作現(xiàn)場記錄
$ git stash list
// 恢復(fù)工作現(xiàn)場
$ git stash apply
$ git stash apply <stash>
// 清除工作現(xiàn)場記錄
$ git stash drop
// 恢復(fù)工作現(xiàn)場并清除記錄
$ git stash pop
遠(yuǎn)程倉庫
// 獲取ssh-key,id_rsa.pub文件中為ssh-key
$ ssh
$ ssh-keygen
// 本地分支關(guān)聯(lián)遠(yuǎn)程倉庫
$ git remote add origin <branch>
// 推送本地到遠(yuǎn)程倉庫中(第一次)
$ git push -u origin <branch>
// 推送本地代碼
$ git push origin <branch>
// 從遠(yuǎn)程倉庫克隆代碼到本地
$ git clone <origin>
// 其他
$ git pull --rebase origin master