Git Fetch无法在裸回购上工作,但git pull在正常回购上有效 [英] Git Fetch fails to work on bare repo, but git pull works on normal repo

查看:78
本文介绍了Git Fetch无法在裸回购上工作,但git pull在正常回购上有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



然而,我对Git非常不感兴趣,所以我甚至无法在这里做一个简单的任务> _< ;.我认为,如果我想出来,我应该可以写出上面的脚本。



(中央回购是git @ localhost:testing中的Gitolite存储库)

/ p>

  cd / tmp 
mkdir / tmp / test
$ git clone git @ localhost:testing
$ git clone git @ localhost:testing testing2
$ git clone git @ localhost:testing --bare

现在当我运行ls时:

  $ ls 
testing testing2 tests.git

现在,我更改testing2中的测试文件,然后将更改推送到中央回购站。

  $ cd testing2 
$ echo'testline'>>测试&& git commit --allow-empty-message -a -m''&& git push

正如预期的那样,如果我在testing文件夹中运行git pull如预期的那样。

  $ cd测试
$ git pull
remote:计数对象:5,完成。
remote:合计3(delta 0),重用0(delta 0)
解包对象:100%(3/3),完成。
从localhost:testing
3242dba..a1ca5ba master - >起源/大师
更新3242dba..a1ca5ba
快进
test | 1 +
1个文件已更改,1个插入(+),0个删除( - )
$ diff ./test ../testing2/test
$

正如上一个diff所示,testing目录和testing2目录完全按照预期工作。 git pull命令同步这两个目录。



然而,如果我cd到testing.git(aka:裸回购),git fetch / git reset -

  $ ls 
分支配置说明HEAD挂钩信息对象packed-refs refs
$ git fetch
remote:计数对象:5,完成。
remote:合计3(delta 0),重用0(delta 0)
解包对象:100%(3/3),完成。
从localhost:测试
*分支HEAD - > FETCH_HEAD
$ git reset --soft
$ cd ..
$ git clone ./testing.git testing3
克隆到testing3 ...
完成。
$ cd testing3
$ diff test ../testing2/test
5a6
> testline

正如您在上一个示例中看到的,裸仓库未能更新,不知怎的,这两个文件之间的差异。我做错了什么?



预先致谢 fetch并未更新 master 分支,只有 FETCH_HEAD (请参阅 FETCH_HEAD 是什么意思?)。



正如我该如何拉到一个裸仓库?,你应该做一个:

  git fetch origin master :master 

或者,对于所有分支

  git fetch origin + refs / heads / *:refs / heads / * 






科林D贝内特补充道:


如果你想定期取这些东西,y ou应该考虑:



  git config remote.origin.fetch + refs / heads / *: refs / heads / * 




可以输入 git fetch 将您的分支与远程同步。

请注意,只有在不需要编辑本地分支的裸仓库中才有意义



First, the big picture: I'm trying to write a git post-receive script for a Redmine / Gitolite server I'm running. As per various recommendations, I'm creating a bare and local repository for Redmine to read from, and I'm setting up a post-receive script on Gitolite to push changes into the Redmine repo.

However, I'm very noobish with Git, so I'm unable to even do a simple task here >_<. I think if I figure this out, I should be able to write the above script. After setting up my test repo, I've created two repos as a test.

(The "Central Repo" is a Gitolite repository at git@localhost:testing)

cd /tmp
mkdir /tmp/test
$ git clone git@localhost:testing
$ git clone git@localhost:testing testing2
$ git clone git@localhost:testing --bare

Now when I run ls:

$ ls
testing  testing2  testing.git

Now, I change the test file inside of the testing2, and then push the changes to the central repo.

$ cd testing2
$ echo 'testline' >> test && git commit --allow-empty-message -a -m '' && git push 

As expected, if I run "git pull" on the "testing" folder, everything works as expected.

$ 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
$

As shown with the last "diff", the "testing" directory and "testing2" directory work exactly as expected. The "git pull" command synchronizes the two directories.

However, if I cd into testing.git (aka: the bare repo), a git fetch / git reset --soft fails to update the bare repo to the latest version.

$ 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

As you can see from the last example, the bare repository failed to get updated, and there is somehow a difference between the two files. What did I do wrong?

Thanks in advance

解决方案

Your fetch hasn't updated the master branch, only FETCH_HEAD (see "What does FETCH_HEAD in Git mean?").

As mentioned in "how do I pull to a bare repository?", you should do a:

git fetch origin master:master

Or, for all the branches:

git fetch origin +refs/heads/*:refs/heads/*


Colin D Bennett added:

If you want to fetch these on a regular basis, you should consider:

git config remote.origin.fetch +refs/heads/*:refs/heads/*

which will allow you to type git fetch to sync your branches with the remote.
Note that this make sense only in a bare repository where local branches are not supposed to be edited.

这篇关于Git Fetch无法在裸回购上工作,但git pull在正常回购上有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆