fetch git pull 切换_git fetch git pull
解析.git文件夾
進入正題之前,我們先來看看.git文件夾
1.config配置文件
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
sharedRepository = group
[remote "origin"]
url = https://xxx/xxx/xxx.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
配置文件可以看出
(1).指定本地master分支對應名為"origin"的遠程庫
(2).名為"origin"的遠程庫的URL(位置)為:https://xxx/xxx/xxx.git
2.HEAD文件
ref: refs/heads/issue178
這表明當前分支是issue178,查看當前分支最新需查看文件 .git/refs/heads/issue178
終端用命令git branch可查看當前所在分支。查看當前分支最新(即HEAD指向)用命令git log
3.refs文件夾
.git/refs/heads文件夾:保存著本地各個分支的信息
.git/refs/remotes 文件夾:其中每一個文件夾代表一個遠程庫名稱(如:origin)
4.logs文件夾
保存的是.git/refs文件夾下相應文件的變更記錄,也就是各個分支變更記錄
git fetch & git pull
1.git fetch:從遠程獲取最新版本到本地,不會自動merge
git checkout issue178
git fetch origin issue178
git log -p issue178..origin/issue178
git merge origin/issue178
解析:
(1).切換到issue178分支
(2).從遠程的origin的issue178主分支下載最新的版本到origin/issue178分支上
(3).比較本地的issue178分支和origin/issue178分支的差別
(4).將origin/issue178分支合并到issue178
上述的另一種清晰的實現:
git checkout issue178
git fetch origin issue178:test
git diff test
git merge test
解析:
(1).切換到issue178分支
(2).從遠程的origin的issue178主分支下載最新的版本到本地的test分支
(3).比較本地的issue178分支和test分支的差別
(4).將test分支合并到issue178
2.git pull:相當于是從遠程獲取最新版本并merge到本地
git checkout issue178
git pull origin issue178
解析:
等同于上述命令。即git pull相當于git fetch 和 git merge
3.Example
(1) git fetch
git fetch origin issue178:issue178
issue178最新id:c75abf94ced40ce49e4807fc0b0fb4b2a3dad7f1
origin issue178最新id:fea9f020b60e9db120395c7ed9c57bd12cd7c085
執行前:
.git/refs/heads/issue178文件內容
c75abf94ced40ce49e4807fc0b0fb4b2a3dad7f1
注:也可查看.git/logs/refs/heads/issue178
.git/refs/remotes/origin/issue178文件內容
c75abf94ced40ce49e4807fc0b0fb4b2a3dad7f1
注:也可查看.git/logs/refs/remotes/origin/issue178
執行后:
.git/refs/heads/issue178文件不變
.git/logs/refs/heads/issue178文件不變
.git/refs/remotes/origin/issue178文件內容變化
fea9f020b60e9db120395c7ed9c57bd12cd7c085
.git/logs/refs/remotes/origin/issue178文件內容變化
(2) git pull
git pull origin issue178:issue178
issue178最新id:c75abf94ced40ce49e4807fc0b0fb4b2a3dad7f1
origin issue178最新id:fea9f020b60e9db120395c7ed9c57bd12cd7c085
執行前:
.git/refs/heads/issue178文件內容
c75abf94ced40ce49e4807fc0b0fb4b2a3dad7f1
注:也可查看.git/logs/refs/heads/issue178
.git/refs/remotes/origin/issue178文件內容
c75abf94ced40ce49e4807fc0b0fb4b2a3dad7f1
注:也可查看.git/logs/refs/remotes/origin/issue178
執行后:
.git/refs/heads/issue178文件內容變化
fea9f020b60e9db120395c7ed9c57bd12cd7c085
.git/logs/refs/heads/issue178文件內容變化
.git/refs/remotes/origin/issue178文件內容不變
.git/logs/refs/remotes/origin/issue178文件內容不變
4.圖示
總結
以上是生活随笔為你收集整理的fetch git pull 切换_git fetch git pull的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: adb 静默安装_怎么实现Android
- 下一篇: python二维图颜色函数_Python