Git:git-pull的用法總結


Git用法總結系列收藏於IT老兵驛站

Git:git-pull的用法總結。

前言

本篇文章總結一下git-pull 的用法,主要過程是基於對官網的完整閱讀,記錄關鍵筆記和樣例,加上自己的理解。整個過程是這樣:
1. 認真讀完官網之后,才會知道它到底有多少內容,這樣要比一次一次碎片化地去查要節省很多的時間,不這樣讀一遍,你怎么能知道git-pull有多少功能呢,如果不知道,回頭遇到了需要這個功能的時候,都不知道怎么去查,要了解這個命令的外延。
2. 當然,很多內容一下子是記不住的。記錄適當的,或者說關鍵性的筆記來輔助記憶,將來可以多次去查看。
3. 記錄學習的心得。

粗讀了一遍git-pull的文檔,內容很多,恐怕一篇筆記不足以總結到位,可能要分為多篇筆記來總結。

正文

語法

git pull的作用是從一個倉庫或者本地的分支拉取並且整合代碼。

git pull [<options>] [<repository> [<refspec>…​]]

描述

git pull相當於 git fetch 跟着一個 git merge FETCH_HEAD<repository>是倉庫的名字,<refspec> 是分支的名字。如果都不寫,會有一個默認值。

一個例子:

     A---B---C master on origin
    /
D---E---F---G master
    ^
    origin/master in your repository

遠程的master分支到了C,本地的開發到了G

     A---B---C origin/master
    /         \
D---E---F---G---H master

git pull之后會生成一個新的H,合並兩個分支。

如果發生了沖突,可以使用git reset --merge進行回退。

options(選項)

下面摘錄幾個常用的選項。

–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 設置的默認跟蹤的服務器和分支來拉取。

實例: 拉取遠程服務器originmaster分支

git pull origin master

總結

git-pull的用法先總結到這里,還有很多需要細化的地方,一口吃不下,需要一口一口來。

參考

https://git-scm.com/docs/git-pull
https://www.atlassian.com/git/tutorials/syncing/git-pull


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM