解析.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,查看当前分支最新<commit>需查看文件 .git/refs/heads/issue178
终端用命令git branch可查看当前所在分支。查看当前分支最新<commit>(即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最新<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文件内容变化
(2) git pull
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文件内容不变
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。