Git分支Branch使用指南

引言: Git因爲其良好的分佈式特性,被廣爲採用,本文將綜述其核心的關鍵指令。java

建立Branch

git checkout -b ‘branch name’git

查看遠程分支

git branch -a服務器

Options:app

-a 查看全部的branch 
-r 查看遠程的branch 
-l 查看本地的brnach分佈式

查看本地分支branch

git branchfetch

切換branch

git checkout ‘branch_name’spa

刪除本地branch

git branch -D br_namecode

刪除遠程branch

git push origin :br (origin 後面有空格)rem

提交指令

新增文件到Git管理之下it

git add xxx.java

提交到本地的Repository

git commit -m ‘comment here’ xxx.java ….

-m : 這裏主要是提交代碼變化的若干註釋 
-a: 指一次提交全部的變化文件列表

push指令

推送到遠程主機的master

git push origin master

將當前分支推送到遠程Repository

git push origin

將本地全部的branch推送到服務器上

git push –all origin

fetch指令

含義: 將遠程的代碼下載到本地,不進行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

Pull 指令

將遠程的代碼下載到本地,並自動進行合併

git pull origin master

通常狀況下,推薦使用fetch,根據實際狀況決定是否與遠程 master代碼進行合併。

Tag指令

建立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

Merge指令

切換到master branch

git checkout master 
將xxx_branch合併到master上 
git merge xxx_branch

查看git master信息

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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

總結

這裏的總結沒法一一覆蓋全部的用法,更多詳細的用法,能夠查看git help,獲取更多信息。

相關文章
相關標籤/搜索