Git的基本操做

 

初始化操做
    $ git config -global user.name <name> #設置提交者名字
    $ git config -global user.email <email> #設置提交者郵箱
    $ git config -global core.editor <editor> #設置默認文本編輯器
    $ git config -global merge.tool <tool> #設置解決合併衝突時差別分析工具
    $ git config -list #檢查已有的配置信息
建立新版本庫
    $ git clone <url> #克隆遠程版本庫
    $ git init #初始化本地版本庫
修改和提交
    $ git add . #添加全部改動過的文件
    $ git add <file> #添加指定的文件
    $ git mv <old> <new> #文件重命名
    $ git rm <file> #刪除文件
    $ git rm -cached <file> #中止跟蹤文件但不刪除
    $ git commit -m <file> #提交指定文件
    $ git commit -m 「commit message」 #提交全部更新過的文件
    $ git commit -amend #修改最後一次提交
    $ git commit -C HEAD -a -amend #增補提交(不會產生新的提交歷史紀錄)
查看提交歷史
    $ git log #查看提交歷史
    $ git log -p <file> #查看指定文件的提交歷史
    $ git blame <file> #以列表方式查看指定文件的提交歷史
    $ gitk #查看當前分支歷史紀錄
    $ gitk <branch> #查看某分支歷史紀錄
    $ gitk --all #查看全部分支歷史紀錄
    $ git branch -v #每一個分支最後的提交
    $ git status #查看當前狀態
    $ git diff #查看變動內容
撤消操做
    $ git reset -hard HEAD #撤消工做目錄中全部未提交文件的修改內容
    $ git checkout HEAD <file1> <file2> #撤消指定的未提交文件的修改內容
    $ git checkout HEAD. #撤消全部文件
    $ git revert <commit> #撤消指定的提交
分支與標籤
    $ git branch #顯示全部本地分支
    $ git checkout <branch/tagname> #切換到指定分支或標籤
    $ git branch <new-branch> #建立新分支
    $ git branch -d <branch> #刪除本地分支
    $ git tag #列出全部本地標籤
    $ git tag <tagname> #基於最新提交建立標籤
    $ git tag -d <tagname> #刪除標籤
合併與衍合
    $ 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>/<tagname> #刪除遠程分支或標籤
    $ git push -tags #上傳全部標籤git

 

附:參考

中文版權威教程Git Pro編輯器

相關文章
相關標籤/搜索