進入正題以前,咱們先來看看.git文件夾
git
[core]fetch
repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true sharedRepository = group
[remote "origin"]url
url = https://xxx/xxx/xxx.git fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]spa
remote = origin merge = refs/heads/master
配置文件能夠看出
(1).指定本地master分支對應名爲"origin"的遠程庫
(2).名爲"origin"的遠程庫的URL(位置)爲:https://xxx/xxx/xxx.git3d
ref: refs/heads/issue178code
這代表當前分支是issue178,查看當前分支最新<commit>需查看文件 .git/refs/heads/issue178
終端用命令git branch可查看當前所在分支。查看當前分支最新<commit>(即HEAD指向)用命令git logorm
.git/refs/heads文件夾:保存着本地各個分支的信息
.git/refs/remotes 文件夾:其中每個文件夾表明一個遠程庫名稱(如:origin)ip
保存的是.git/refs文件夾下相應文件的變動記錄,也就是各個分支變動記錄rem
git checkout issue178
git fetch origin issue178
git log -p issue178..origin/issue178
git merge origin/issue178get
解析:
(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
git checkout issue178
git pull origin issue178
解析:
等同於上述命令。即git pull至關於git fetch 和 git merge
git fetch origin issue178:issue178
issue178最新<commit>id:c75abf94ced40ce49e4807fc0b0fb4b2a3dad7f1
origin issue178最新<commit>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文件內容變化
git pull origin issue178:issue178
issue178最新<commit>id:c75abf94ced40ce49e4807fc0b0fb4b2a3dad7f1
origin issue178最新<commit>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文件內容不變