git操作命令
配置
配置用戶信息
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
配置文本編輯器
git config --global core.editor vim
配置差異分析工具-- kdiff3,tkdiff,meld,xxdiff,emerge,vimdiff,gvimdiff,ecmerge,opendiff
git config --global merge.tool vimdiff
參看配置信息
git config --list
幫助
git help <verb>
初始化
倉庫初始化
git init
git add *.c
git add README
git commit -m 'initial project version'
git remote add <shortname> <url>
git push [remote-name] [branch-name]
從現有倉庫克隆
git clone git://github.com/schacon/grit.git
git clone git://github.com/schacon/grit.git mygrit
</blockquote>
參看
查看文件狀態
git status
查看當前文件和暫存區差異,當前文件上次提交文件差異
git diff
git diff <file>
查看暫存文件和上次提交差異
git diff --cached
參看歷史
git log
log可視化
gitk
提交
提交更新
git commit
跳過使用暫存區提交
git commit -a -m 'added new benchmarks'
撤銷
撤銷提交
git commit --amend
取消暫存
git reset HEAD <file>
取消對文件的修改
git checkout -- <file>
文件操作
移除文件
git rm <file>
只從跟蹤清單中刪除,文件不刪除
git rm --cached readme.txt
移動文件
git mv file_from file_to
增加追蹤文件
git add <file>
遠程倉庫
參看克隆的遠程倉庫
git remote -v
添加遠程倉庫(給遠程路徑取個別名)
git remote add [shortname] [url]
git remote add pb git://github.com/paulboone/ticgit.git
抓取遠程倉庫,不會合并
git fetch [remote-name]
git fetch pb
推送數據到遠程倉庫
git push [remote-name] [branch-name]
參看遠程倉庫信息
git remote show [remote-name]
更改倉庫名稱
git remote rename [old-name] [new-name]
git remote rename pb paul
分支
參看本地分支
git branch
查看遠程分支
git branch -a
切換分支
git checkout <local-branch>
創建分支,從本地當前分支創建新的分支
git branch <new-local-branch>
創建分支,從本地其他分支創建新的分支
git branch <new-local-branch> <old-local-branch>
創建分支,從遠程分支創建一個本地分支
git branch <new-local-branch> <remote>/<remote-branch>
創建并切換分支
git checkout -b <new-local-branch>
git checkout -b <new-local-branch> <old-local-branch>
git checkout -b <new-local-branch> <remote>/<remote-branch>
刪除本地分支
git branch -d <local-branch>
刪除遠端分支
git push <remote-name> :<remote-branch>
合并本地其他分支到當前分支
git merge <local-branch>
合并遠端到本地的當前分支
git pull [remote] <remote-branch>
創建遠程分支,提交到遠端分支
git push <remote> <local-branch>
取出我在本地的local-branch分支,推送到遠程倉庫的同名分支中去,遠端無同名分支則創建同名分支
</blockquote> 創建遠程分支,提交到遠端分支
git push <remote> <local-branch]:[remote-branch]
取出我在本地的local-branch分支,推送到遠程倉庫的remote-branch分支中去,遠端無remote-branch分支則創建remote-branch分支
</blockquote>
設置本地分支跟蹤遠端分支
git branch --set-upstream-to=origin/遠端分支 本地分支
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!