Git Fetch无法在裸仓库上运行,但git pull适用于普通仓库

Dra*_*788 11 git

首先,大局:我正在尝试为我正在运行的Redmine/Gitolite服务器编写一个git post-receive脚本.根据各种建议,我正在为Redmine创建一个裸的本地存储库来读取,我正在Gitolite上设置一个接收后脚本,以便将更改推送到Redmine存储库中.

但是,我对Git非常苛刻,所以我甚至无法在这里做一个简单的任务> _ <.我想如果我弄清楚这一点,我应该能够编写上面的脚本.在设置我的测试回购后,我创建了两个repos作为测试.

("Central Repo"是git @ localhost:测试中的Gitolite存储库)

cd /tmp
mkdir /tmp/test
$ git clone git@localhost:testing
$ git clone git@localhost:testing testing2
$ git clone git@localhost:testing --bare
Run Code Online (Sandbox Code Playgroud)

现在当我运行ls时:

$ ls
testing  testing2  testing.git
Run Code Online (Sandbox Code Playgroud)

现在,我更改了测试2中的测试文件,然后将更改推送到中央存储库.

$ cd testing2
$ echo 'testline' >> test && git commit --allow-empty-message -a -m '' && git push 
Run Code Online (Sandbox Code Playgroud)

正如所料,如果我在"testing"文件夹上运行"git pull",一切都按预期工作.

$ cd testing
$ git pull
remote: Counting objects: 5, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From localhost:testing
   3242dba..a1ca5ba  master     -> origin/master
Updating 3242dba..a1ca5ba
Fast-forward
 test |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
$ diff ./test ../testing2/test
$
Run Code Online (Sandbox Code Playgroud)

如最后一个"diff"所示,"testing"目录和"testing2"目录完全按预期工作."git pull"命令同步两个目录.

但是,如果我进入testing.git(又名:裸仓库),git fetch/git reset --soft无法将裸仓库更新到最新版本.

$ ls
branches  config  description  HEAD  hooks  info  objects  packed-refs  refs
$ git fetch
remote: Counting objects: 5, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From localhost:testing
 * branch            HEAD       -> FETCH_HEAD
$ git reset --soft
$ cd ..
$ git clone ./testing.git testing3
Cloning into testing3...
done.
$ cd testing3
$ diff test ../testing2/test
5a6
> testline
Run Code Online (Sandbox Code Playgroud)

从上一个示例中可以看出,裸存储库无法更新,并且两个文件之间存在某种差异.我做错了什么?

提前致谢

Von*_*onC 26

你的fetch master只是没有更新分支FETCH_HEAD(参见" Git中的含义是什么FETCH_HEAD意思? ").

如" 我如何拉到裸存储库? "中所述,您应该执行以下操作:

git fetch origin master:master
Run Code Online (Sandbox Code Playgroud)

或者,对于所有分支:

git fetch origin +refs/heads/*:refs/heads/*
Run Code Online (Sandbox Code Playgroud)

Colin D Bennett补充道:

如果您想定期获取这些内容,您应该考虑:

git config remote.origin.fetch +refs/heads/*:refs/heads/*
Run Code Online (Sandbox Code Playgroud)

这将允许您键入git fetch以将分支与远程同步.
请注意,这仅适用于不应编辑本地分支的裸存储库.

  • 如果你想定期获取它们,你应该考虑:``git config remote.origin.fetch + refs/heads/*:refs/heads/*``,这将允许你输入``git fetch` `将分支与遥控器同步.请注意,这仅适用于不应编辑本地分支的裸存储库. (6认同)