第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Git fetch和git pull的區(qū)別

Git fetch和git pull的區(qū)別

Git
Qyouu 2019-02-19 19:12:11
Git fetch和git pull的區(qū)別
查看完整描述

2 回答

?
ibeautiful

TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊

每一個(gè)本地庫(kù)下都有一個(gè).git的隱藏文件夾,文件夾中的文件保存著跟這個(gè)本地庫(kù)相關(guān)的信息
首先來(lái)看下其中的config文件
[plain] view plain copy
[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
從這個(gè)文件中我們可以了解到:
1,本地庫(kù)的當(dāng)前分支為master,其關(guān)聯(lián)的遠(yuǎn)程庫(kù)名稱(chēng)為origin(不同的名稱(chēng)可以指向同一個(gè)遠(yuǎn)程庫(kù),參見(jiàn)git remote命令)
2,遠(yuǎn)程庫(kù)origin所在的位置為(URL):git@github.com:seanzou88/fetch.git
然后可以查看.git文件夾下的HEAD文件:
[plain] view plain copy
ref: refs/heads/master
其指向.git\refs\heads\master文件
[plain] view plain copy
ce71505b3626a3648b2c32ea2081d65049cad300
這個(gè)文件中保存的是本地庫(kù)中最新的commit id
.git\refs文件夾很有意思,面分為3個(gè)文件夾
heads文件夾前面說(shuō)過(guò)了
remotes文件夾中的每一個(gè)文件夾代表一個(gè)遠(yuǎn)程庫(kù)名稱(chēng)(git remote),其中的每個(gè)文件關(guān)聯(lián)遠(yuǎn)程庫(kù)的一個(gè)分支,其中保存該分支的最新commit id
.git\logs文件夾下保存的是.git\refs文件夾下相應(yīng)文件的變更記錄
準(zhǔn)備工作到此結(jié)束,下面可以具體看看git fetch和git pull之間的區(qū)別了

git fetch origin
本地的latest commit id為:ce71505b3626a3648b2c32ea2081d65049cad300
githup上的latest commit id為:ab8cd391f978fe5384a78c92001ef8ae861046f0
before:
.git\refs\heads\master
[plain] view plain copy
ce71505b3626a3648b2c32ea2081d65049cad300
.git\refs\remotes\origin\master
[plain] view plain copy
ce71505b3626a3648b2c32ea2081d65049cad300
.git\logs\refs\heads\master
[plain] view plain copy
0000000000000000000000000000000000000000
ce71505b3626a3648b2c32ea2081d65049cad300
......
commit (initial): first commit
.git\logs\refs\remotes\origin\master
[plain] view plain copy
0000000000000000000000000000000000000000
ce71505b3626a3648b2c32ea2081d65049cad300
......
update by push
after:
.git\refs\heads\master(不變)
.git\refs\remotes\origin\master
[plain] view plain copy
ab8cd391f978fe5384a78c92001ef8ae861046f0
.git\logs\refs\heads\master(不變)
.git\logs\refs\remotes\origin\master
[plain] view plain copy
0000000000000000000000000000000000000000
ce71505b3626a3648b2c32ea2081d65049cad300
......
update by push
ce71505b3626a3648b2c32ea2081d65049cad300
ab8cd391f978fe5384a78c92001ef8ae861046f0
......
fetch origin: fast-forward
本地庫(kù)并沒(méi)有變化,也就是說(shuō),git fetch只會(huì)將本地庫(kù)所關(guān)聯(lián)的遠(yuǎn)程庫(kù)的commit id更新至最新
HEAD沒(méi)有變化很容易理解,因?yàn)楸镜貛?kù)并沒(méi)有變化

git pull origin master:master
本地的latest commit id為:3643a1a65fc88ae0e9f28f12168629758d027415
githup上的latest commit id為:64df093f73294d82a3adce9694871b9fac2aecfb
before:
.git\refs\heads\master
[plain] view plain copy
3643a1a65fc88ae0e9f28f12168629758d027415
.git\refs\remotes\origin\master
[plain] view plain copy
3643a1a65fc88ae0e9f28f12168629758d027415
.git\logs\refs\heads\master
[plain] view plain copy
0000000000000000000000000000000000000000
3643a1a65fc88ae0e9f28f12168629758d027415
......
commit (initial): first commit
.git\logs\refs\remotes\origin\master
[plain] view plain copy
0000000000000000000000000000000000000000
3643a1a65fc88ae0e9f28f12168629758d027415
......
update by push
after:
.git\refs\heads\master
[plain] view plain copy
64df093f73294d82a3adce9694871b9fac2aecfb
.git\refs\remotes\origin\master(不變)
.git\logs\refs\heads\master
[plain] view plain copy
0000000000000000000000000000000000000000
3643a1a65fc88ae0e9f28f12168629758d027415
......
commit (initial): first commit
3643a1a65fc88ae0e9f28f12168629758d027415
64df093f73294d82a3adce9694871b9fac2aecfb
......
pull origin master:master: fast-forward
.git\logs\refs\remotes\origin\master(不變)
本地庫(kù)更新至最新,git pull會(huì)將本地庫(kù)更新至遠(yuǎn)程庫(kù)的最新?tīng)顟B(tài)
由于本地庫(kù)進(jìn)行了更新,HEAD也會(huì)相應(yīng)的指向最新的commit id
所以雖然從結(jié)果上來(lái)看,git pull = git fetch + git merge,但是從文件中保存的commit id來(lái)看,實(shí)現(xiàn)上不是這樣實(shí)現(xiàn)的



查看完整回答
反對(duì) 回復(fù) 2019-03-02
?
繁星點(diǎn)點(diǎn)滴滴

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊

Git中從遠(yuǎn)程的分支獲取最新的版本到本地有這樣2個(gè)命令:
1. git fetch:相當(dāng)于是從遠(yuǎn)程獲取最新版本到本地,不會(huì)自動(dòng)merge

git fetch origin master
git log -p master..origin/master
git merge origin/master
以上命令的含義:
首先從遠(yuǎn)程的origin的master主分支下載最新的版本到origin/master分支上
然后比較本地的master分支和origin/master分支的差別
最后進(jìn)行合并
上述過(guò)程其實(shí)可以用以下更清晰的方式來(lái)進(jìn)行:

git fetch origin master:tmp
git diff tmp
git merge tmp
從遠(yuǎn)程獲取最新的版本到本地的test分支上
之后再進(jìn)行比較合并
2. git pull:相當(dāng)于是從遠(yuǎn)程獲取最新版本并merge到本地

git pull origin master

上述命令其實(shí)相當(dāng)于git fetch 和 git merge
在實(shí)際使用中,git fetch更安全一些
因?yàn)樵趍erge前,我們可以查看更新情況,然后再?zèng)Q定是否合并


查看完整回答
反對(duì) 回復(fù) 2019-03-02
  • 2 回答
  • 0 關(guān)注
  • 790 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)