[版本控制之道] Git 經常使用的命令總結(歡迎收藏備用)

堅持天天學習,堅持天天覆習,技術永遠學不完,本身永遠要前進html

總結平常開發生產中經常使用的Git版本控制命令git

------------------------------main--------------------------------學習

<極客鎮樓>fetch

一 建立版本庫

$ git clone <url>                 #克隆遠程版本庫 url爲git遠程庫的地址
$ git init                        #初始化本地版本庫

二 修改和提交

$ git status                      #查詢狀態 
$ git diff                        #查看變動內容
$ 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       #撤銷工做目錄中全部未提交文件的修改內容
$ git check HEAD <file>       #撤銷制定的位提交文件的修改內容
$ git revert <commit>         #撤銷制定的提交

 五 分之與標籤

$ git branch                      #顯示全部本地分支
$ git checkout <branch/tag>       #切換到制定分支或標籤
$ git branch -d <branch>          #刪除本地分支
$ git branch <new-branch>         #建立新分支
$ git tag                         #列出全部本地標籤
$ git tag <tagname>               #基於最新提交建立標籤
$ git tag -d <branch>        #刪除標籤

六 合併與衍合

$ git merge <branch>          #合併指定分支到當前分支

  $ git rebase <branch>        #衍合制定分支到當前分支url

七 遠程操做

$ git remote -v                 #查看遠程版本庫信息
$ git remote show <remote>          #查看指定遠程版本庫信息
$ git remote add <remote> <url>        #添加遠程版本庫
$ git remote fetch <remote> <branch>    #從遠程代碼庫獲取代碼
$ git pull <remote> <branch>        #下載代碼及快速合併
$ git push <remote> <branch>         #上傳代碼及快速合併
$ git push <remote> :<branch/tag-name>   #刪除遠程分支或標籤
$ git push --tags                        #上傳全部標籤

八  查詢用戶和設置用戶spa

  1. 查看用戶名和郵箱地址:版本控制

    $ git config user.name
    
    $ git config user.email
  2. 修改用戶名和郵箱地址:code

    $ git config --global user.name "username"
    
    $ git config --global user.email "email"

----------------end----------------htm

原創,轉發請註明出處:http://www.cnblogs.com/hyhnet/p/5849370.htmlblog

交流WX:wixf150

相關文章
相關標籤/搜索