日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

git fetch和git pull之间的区别--转载

發(fā)布時間:2025/4/5 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 git fetch和git pull之间的区别--转载 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原文地址:http://blog.csdn.net/a19881029/article/details/42245955

?

git fetch和git pull都可以用來更新本地庫,它們之間有什么區(qū)別呢?

每一個本地庫下都有一個.git的隱藏文件夾,文件夾中的文件保存著跟這個本地庫相關的信息

首先來看下其中的config文件

[plain]?view plaincopy
  • [core]??
  • ????repositoryformatversion?=?0??
  • ????filemode?=?false??
  • ????bare?=?false??
  • ????logallrefupdates?=?true??
  • ????symlinks?=?false??
  • ????ignorecase?=?true??
  • ????hideDotFiles?=?dotGitOnly??
  • [remote?"origin"]??
  • ????url?=?git@github.com:seanzou88/fetch.git??
  • ????fetch?=?+refs/heads/*:refs/remotes/origin/*??
  • [branch?"master"]??
  • ????remote?=?origin??
  • ????merge?=?refs/heads/master??
  • 從這個文件中我們可以了解到:

    1,本地庫的當前分支為master,其關聯(lián)的遠程庫名稱為origin(不同的名稱可以指向同一個遠程庫,參見git remote命令)

    2,遠程庫origin所在的位置為(URL):git@github.com:seanzou88/fetch.git

    然后可以查看.git文件夾下的HEAD文件:

    [plain]?view plaincopy
  • ref:?refs/heads/master??
  • 其指向.git\refs\heads\master文件

    [plain]?view plaincopy
  • ce71505b3626a3648b2c32ea2081d65049cad300??
  • 這個文件中保存的是本地庫中最新的commit id

    .git\refs文件夾很有意思,面分為3個文件夾

    heads文件夾前面說過了

    remotes文件夾中的每一個文件夾代表一個遠程庫名稱(git remote),其中的每個文件關聯(lián)遠程庫的一個分支,其中保存該分支的最新commit id

    .git\logs文件夾下保存的是.git\refs文件夾下相應文件的變更記錄

    準備工作到此結束,下面可以具體看看git fetch和git pull之間的區(qū)別了

    ?

    git fetch origin

    本地的latest commit id為:ce71505b3626a3648b2c32ea2081d65049cad300

    githup上的latest commit id為:ab8cd391f978fe5384a78c92001ef8ae861046f0

    before:

    .git\refs\heads\master

    [plain]?view plaincopy
  • ce71505b3626a3648b2c32ea2081d65049cad300??
  • .git\refs\remotes\origin\master

    [plain]?view plaincopy
  • ce71505b3626a3648b2c32ea2081d65049cad300??
  • .git\logs\refs\heads\master

    [plain]?view plaincopy
  • 0000000000000000000000000000000000000000???
  • ????????ce71505b3626a3648b2c32ea2081d65049cad300???
  • ????????......????
  • ????????commit?(initial):?first?commit???
  • .git\logs\refs\remotes\origin\master

    [plain]?view plaincopy
  • 0000000000000000000000000000000000000000???
  • ????????ce71505b3626a3648b2c32ea2081d65049cad300???
  • ????????......????
  • ????????update?by?push??
  • after:

    .git\refs\heads\master(不變)

    .git\refs\remotes\origin\master

    [plain]?view plaincopy
  • ab8cd391f978fe5384a78c92001ef8ae861046f0??
  • .git\logs\refs\heads\master(不變)

    .git\logs\refs\remotes\origin\master

    [plain]?view plaincopy
  • 0000000000000000000000000000000000000000???
  • ????????ce71505b3626a3648b2c32ea2081d65049cad300???
  • ????????......????????
  • ????????update?by?push??
  • ce71505b3626a3648b2c32ea2081d65049cad300???
  • ????????ab8cd391f978fe5384a78c92001ef8ae861046f0???
  • ????????......????
  • ????????fetch?origin:?fast-forward??
  • 本地庫并沒有變化,也就是說,git fetch只會將本地庫所關聯(lián)的遠程庫的commit id更新至最新

    HEAD沒有變化很容易理解,因為本地庫并沒有變化

    ?

    git pull origin master:master

    本地的latest commit id為:3643a1a65fc88ae0e9f28f12168629758d027415

    githup上的latest commit id為:64df093f73294d82a3adce9694871b9fac2aecfb

    before:

    .git\refs\heads\master

    [plain]?view plaincopy
  • 3643a1a65fc88ae0e9f28f12168629758d027415??
  • .git\refs\remotes\origin\master

    [plain]?view plaincopy
  • 3643a1a65fc88ae0e9f28f12168629758d027415??
  • .git\logs\refs\heads\master

    [plain]?view plaincopy
  • 0000000000000000000000000000000000000000???
  • ????????3643a1a65fc88ae0e9f28f12168629758d027415???
  • ????????......????
  • ????????commit?(initial):?first?commit??
  • .git\logs\refs\remotes\origin\master

    [plain]?view plaincopy
  • 0000000000000000000000000000000000000000???
  • ????????3643a1a65fc88ae0e9f28f12168629758d027415???
  • ????????......????
  • ????????update?by?push??
  • after:

    .git\refs\heads\master

    [plain]?view plaincopy
  • 64df093f73294d82a3adce9694871b9fac2aecfb??
  • .git\refs\remotes\origin\master(不變)

    .git\logs\refs\heads\master

    [plain]?view plaincopy
  • 0000000000000000000000000000000000000000???
  • ????????3643a1a65fc88ae0e9f28f12168629758d027415???
  • ????????......????
  • ????????commit?(initial):?first?commit??
  • 3643a1a65fc88ae0e9f28f12168629758d027415???
  • ????????64df093f73294d82a3adce9694871b9fac2aecfb???
  • ????????......????
  • ????????pull?origin?master:master:?fast-forward??
  • .git\logs\refs\remotes\origin\master(不變)

    本地庫更新至最新,git pull會將本地庫更新至遠程庫的最新狀態(tài)

    由于本地庫進行了更新,HEAD也會相應的指向最新的commit id

    所以雖然從結果上來看,git pull = git fetch + git merge,但是從文件中保存的commit id來看,實現上不是這樣實現的

    為了更好的理解,畫了個圖:

    ?

    轉載于:https://www.cnblogs.com/davidwang456/p/4511245.html

    總結

    以上是生活随笔為你收集整理的git fetch和git pull之间的区别--转载的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。