引言: Git因爲其良好的分佈式特性,被廣爲採用,本文將綜述其核心的關鍵指令。java
git checkout -b ‘branch name’git
git branch -a服務器
Options:app
-a 查看全部的branch
-r 查看遠程的branch
-l 查看本地的brnach分佈式
git branchfetch
git checkout ‘branch_name’spa
git branch -D br_namecode
git push origin :br (origin 後面有空格)rem
新增文件到Git管理之下it
git add xxx.java
提交到本地的Repository
git commit -m ‘comment here’ xxx.java ….
-m : 這裏主要是提交代碼變化的若干註釋
-a: 指一次提交全部的變化文件列表
推送到遠程主機的master
git push origin master
將當前分支推送到遠程Repository
git push origin
將本地全部的branch推送到服務器上
git push –all origin
含義: 將遠程的代碼下載到本地,不進行merge
git fetch origin master
查看本地master與遠程master之間的差異
git log -p master..origin/master
合併代碼
git merge origin/master
另一種更爲明確的作法是當遠程的代碼下載到本地做爲一個branch,而後合併
git fetch origin master:t-branch
git diff t-branch
git merge t-branch
將遠程的代碼下載到本地,並自動進行合併
git pull origin master
通常狀況下,推薦使用fetch,根據實際狀況決定是否與遠程 master代碼進行合併。
建立Tag
git tag -a ‘tag_name_v0.1.2’ -m ‘comment message’
查詢當前全部的tag
git tag
按照模式匹配來查詢Tags
git tag -l ‘v0.1.*’
將當前的特定tag推送到遠程
git push origin tag_name
將當前全部的tag都推送到遠程
git push origin –all tags
切換到master branch
git checkout master
將xxx_branch合併到master上
git merge xxx_branch
git remote show origin
* remote origin Fetch URL: http://source.xx.com/app/xx-ImageService.git Push URL: http://source.xx.com/app/xx-ImageService.git HEAD branch: master Remote branch: master tracked Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (fast-forwardable)
這裏的總結沒法一一覆蓋全部的用法,更多詳細的用法,能夠查看git help,獲取更多信息。