常用命令
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty Git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
常用命令行
master 默認開發(fā)主干分支
origin 默認遠程版本庫
Head 默認開發(fā)分支
Head^ Head的福提交
- 版本庫
git clone <url> #克隆遠端版本庫
git init #初始化本地版本庫
- 分支與標簽
git branch #查看所有本地分支
git branch -a #查看所有分支
git branch -r #查看所有遠端分支
git branch <new branch> #創(chuàng)建新分支
git branch <branch2> <branch1> #以branch1分支為基礎創(chuàng)建branch2分支
git branch -d <branch> #刪除本地分支
git branch -m <oldbranch> <newbranch>#分支重命名
git checkout <branch/tag> #切換到指定分支或者標簽
git tag #查看所有本地標簽
git tag <new tag> #基于最新提交創(chuàng)建標簽
git tag -d <tag> #刪除標簽
- 修改和提交代碼
git status #查看當前狀態(tài)
git diff #查看變更內(nèi)容
git add . #把所有變動的文件添加到暫存區(qū)
git add <file> #把指定的文件添加到暫存區(qū)
git mv <oldname> <newname> #文件更名
git rm <file> #刪除文件
git rm --cached <file> #停止跟蹤文件但不刪除
git commit -m '<commit message>' #提交文件
git commit --amend #對上一次的提交進行修改。既可以對上次提交的內(nèi)容進行修改,也可以修改提交說明
- 合并與衍合
git merge <branch> #合并指定分支的代碼到當前分支
git rebase <branch> #衍合指定分支到當前分支
- 遠程操作
git remote -v #查看遠程版本庫信息
git remote show <remote> #查看指定遠程版本庫信息
git remote add <remote> <url> #添加遠程版本庫
git fetch <remote> #從遠程庫獲取代碼
git pull <remote> <branch> #下載代碼及快速合并
git push <remote> <branch> #上傳代碼及快速合并
git push <remote> :<branch/tag> #刪除遠程分支或標簽
git push --tags #上傳所有標簽
- 撤銷
git reset --hard HEAD #撤銷工作目錄中所有未提交文件的修改
git checkout HEAD <file> #撤銷指定的未提交文件的修改
git revert <commit> #撤銷指定的提交
- 其他
git log #查看提交歷史
git log -p <file> #查看指定文件的提交歷史
git blame <file> #以列表方式查看指定文件的提交歷史
git stash push #將文件給push到一個臨時空間中
git stash pop #將文件從臨時空間pop下來
匯總常用的一些操作
git checkout -b dev #創(chuàng)建新的本地分支并切換到新分支,等價于
git branch dev
git checkout dev
#提交代碼
git add
git commit
git status #查看當前狀態(tài)
git remote show #查看遠程庫
git remote show origin #查看遠程庫origin里邊的資源
git merge origin/dev #將遠程dev分支與當前分支進行合并
git push origin master #將本地項目給提交到服務器中
git代碼發(fā)布流程
假如開發(fā)分支為dev 線上分支為online
- 創(chuàng)建功能分支 dev
git checkout -b dev
- 功能迭代
(dev) git commit
- 合并最新線上分支代碼到開發(fā)分支
(dev) git checkout online
(online) git pull
(online) git checkout dev
(dev) git merge online
#解決沖突
(dev) git commit
- 功能迭代
(dev) git commit
- 測試通過,合并代碼到線上的online分支
#先執(zhí)行一遍第三步,也就是合并最新線上分支代碼到開發(fā)分支,以防沖突
(dev) git checkout online
(online) git merge dev --squash
(online) git commit #
推送到遠端,正常結束
(online) git push origin
如果這一步被拒絕,是因為online有更新的代碼提交了,為了防止online上出現(xiàn)沖突,需要重新執(zhí)行這一步
參考文檔
Git 常用命令速查表(圖文+表格) https://www.cnblogs.com/kenshinobiy/p/4543976.html