創(chuàng)建版本庫
$ git clone <url>
#克隆遠(yuǎn)程版本庫
$ git init #初始化本地版本庫
修改和提交
$ git status #查看狀態(tài) $ git diff #查看變更內(nèi)容 $ git add . #跟蹤所有改動過的文件 $ git add <file> #跟蹤指定的文件 $ git mv <old> < new > #文件改名 $ git rm <file> #刪除文件 $ git rm --cached <file> #停止跟蹤文件但不刪除 $ git commit - m “commit message” #提交所有更新過的文件 $ git commit --amend #修改最后一次提交
查看提交歷史
$ git log #查看提交歷史 $ git log -p <file> #查看指定文件的提交歷史 $ git blame <file> #以列表方式查看指定文件的提交歷史
撤消
$ git reset -- hard HEAD #撤消工作目錄中所有未提交文件的修改內(nèi)容 $ git checkout HEAD <file> #撤消指定的未提交文件的修改內(nèi)容 $ git checkout --<File> #讓這個文件回到最近一次commit或add時的狀態(tài) $ git revert <commit> #撤消指定的提交
分支與標(biāo)簽
$ git branch #顯示所有本地分支 $ git checkout <branch/tag> #切換到指定分支或標(biāo)簽 $ git checkout -c <branch/tag> #創(chuàng)建并切換到指定分支或標(biāo)簽 $ git branch < new -branch> #創(chuàng)建新分支 $ git branch -d <branch> #刪除本地分支 $ git tag #列出所有本地標(biāo)簽 $ git tag -a tagname -m " " #可以指定標(biāo)簽信息 # git show #可以查看標(biāo)簽詳細(xì)信息 $ git tag <tagname> #基于最新提交創(chuàng)建標(biāo)簽 $ git tag -d <tagname> #刪除標(biāo)簽 $ git push origin tagname #可以推送一個本地標(biāo)簽 $ git push origin -- tags #可以推送全部未推送過的本地標(biāo)簽 $ git tag - d tagname #可以刪除一個本地標(biāo)簽 $ git push origin :refs /tags/tagname #可以刪除一個遠(yuǎn)程標(biāo)簽
合并與衍合
$ git merge <branch>
#合并指定分支到當(dāng)前分支
$ git rebase
<branch> #衍合指定分支到當(dāng)前分支
遠(yuǎn)程操作
$ git remote - v #查看遠(yuǎn)程版本庫信息 $ git remote show <remote> #查看指定遠(yuǎn)程版本庫信息 $ git remote add <remote> <url> #添加遠(yuǎn)程版本庫 $ git fetch <remote> #從遠(yuǎn)程庫獲取代碼 $ git pull <remote> <branch> #下載代碼及快速合并 $ git push <remote> <branch> #上傳代碼及快速合并 $ git push <remote> :<branch/tag-name> #刪除遠(yuǎn)程分支或標(biāo)簽 $ git push --tags #上傳所有標(biāo)簽
GIT常用命令
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
