Git:git-pull的用法總結。
html
本篇文章總結一下git-pull
的用法,主要過程是基於對官網的完整閱讀,記錄關鍵筆記和樣例,加上本身的理解。整個過程是這樣:
1. 認真讀完官網以後,纔會知道它到底有多少內容,這樣要比一次一次碎片化地去查要節省不少的時間,不這樣讀一遍,你怎麼能知道git-pull
有多少功能呢,若是不知道,回頭遇到了須要這個功能的時候,都不知道怎麼去查,要了解這個命令的外延。
2. 固然,不少內容一會兒是記不住的。記錄適當的,或者說關鍵性的筆記來輔助記憶,未來能夠屢次去查看。
3. 記錄學習的心得。git
粗讀了一遍git-pull
的文檔,內容不少,恐怕一篇筆記不足以總結到位,可能要分爲多篇筆記來總結。服務器
git pull的做用是從一個倉庫或者本地的分支拉取而且整合代碼。less
git pull [<options>] [<repository> [<refspec>…]]
git pull
至關於 git fetch
跟着一個 git merge FETCH_HEAD
。<repository>
是倉庫的名字,<refspec>
是分支的名字。若是都不寫,會有一個默認值。ide
一個例子:學習
A---B---C master on origin / D---E---F---G master ^ origin/master in your repository
遠程的master
分支到了C
,本地的開發到了G
。fetch
A---B---C origin/master / \ D---E---F---G---H master
git pull
以後會生成一個新的H
,合併兩個分支。this
若是發生了衝突,可使用git reset --merge
進行回退。spa
下面摘錄幾個經常使用的選項。code
–allow-unrelated-histories
By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently. As that is a very rare
occasion, no configuration variable to enable this by default exists and will not be added.
容許無關的歷史,這個選項,更可能是在更改遠程倉庫的時候用到。
–ff
When the merge resolves as a fast-forward, only update the branch pointer, without creating a merge commit. This is the default behavior.
–no-ff
Create a merge commit even when the merge resolves as a fast-forward. This is the default behaviour when merging an annotated (and possibly signed) tag that is not stored in its natural place in refs/tags/ hierarchy.
–ff-only
Refuse to merge and exit with a non-zero status unless the current HEAD is already up to date or the merge can be resolved as a fast-forward.
ff
選項,這幾個選項是說合並時是否開啓fast-forward
,快速合併,這個有在另一篇帖子中詳細講解,這裏就不贅述了。
實例:默認使用方式
git pull
按照git branch
設置的默認跟蹤的服務器和分支來拉取。
實例: 拉取遠程服務器origin
的master
分支
git pull origin master
git-pull的用法先總結到這裏,還有不少須要細化的地方,一口吃不下,須要一口一口來。
https://git-scm.com/docs/git-pull
https://www.atlassian.com/git/tutorials/syncing/git-pull