从同事的电脑克隆,现在从Bitbucket拉下来仍然下载很多

时间:2016-01-16 15:18:06

标签: git

我们有一个非常庞大的Git存储库,我们处于非常慢的Internet连接之后。

我的同事已经有了最近的存储库副本,所以我做了一个

git clone him:/home/foo/repo
局域网中的

- 速度很快:)

之后,他做了一些修改,所以我做了git pull。在那段时间里,我和我合并了冲突。

接下来,我做了

git remote rename origin him
git remote add <BITBUCKETURL>

我做了一些修改并试图

git push origin master

被拒绝(没有快进)。

所以我试过

git pull origin

但是现在,Git想要下载数兆字节的数据,我不明白。 我认为Git足够智能,可以交叉匹配已有的对象。对?另外,我尝试克隆并添加Bitbucket URL而不进行任何合并;同样的问题。

我该怎么做才能解决这个问题?

编辑以解决评论中的问题

  • 我知道没有其他分支,git pull origin master具有相同的效果
  • 做git pull origin master打印:remote: Counting objects: 1535 - 在此期间没有机会完成这么多机会。
  • 我确实比较了日志,网上没有变化(Bitbucket),这些变化不在我从中克隆的同事的计算机上

2 个答案:

答案 0 :(得分:3)

这不是一个直接的答案,但对于评论来说太大了。 我只是试图重现你的情况,它按预期的方式工作(没有从bitbucket下载拉。)

为什么这对您不起作用的一些可能原因:

1)检查同事存储库 - 它是否具有正确的remotes设置?我不确定,但可能git使用遥控器元数据来理解存储库之间的关系(只是猜测)

2)也许同事的存储库与bitbucket不是最新的?因此,当您执行拉动时,它只会下载新数据。尝试先更新同事的存储库。

这是我用来检查问题的shell脚本,你可以玩这样的东西找出导致你看到的行为的原因:

# Change this to your repository url
BITBUCKET_URL=git@bitbucket.org:user/project

git clone $BITBUCKET_URL project
# Cloning into 'project'...
# Warning: Permanently added the RSA host key for IP address 'xxx.xxx.xxx.xxx' to the list of known hosts.
# remote: Counting objects: 163, done.
# remote: Compressing objects: 100% (154/154), done.
# remote: Total 163 (delta 53), reused 0 (delta 0)
# Receiving objects: 100% (163/163), 3.62 MiB | 1.30 MiB/s, done.
# Resolving deltas: 100% (53/53), done.
# Checking connectivity... done.

mkdir mycopy
cd mycopy
git clone ../project .
# Cloning into '.'...
# done.
ls
# application.py  database.py  README.md  requirements.txt  static
git remote -v show
# origin    /home/seb/test/gitdist/mycopy/../project (fetch)
# origin    /home/seb/test/gitdist/mycopy/../project (push)

git remote rename origin local
git remote add origin $BITBUCKET_URL
git remote -v show
# local /home/seb/test/gitdist/mycopy/../project (fetch)
# local /home/seb/test/gitdist/mycopy/../project (push)
# origin    git@bitbucket.org:owner/project.git (fetch)
# origin    git@bitbucket.org:owner/project.git (push)

git pull origin
# Warning: Permanently added the RSA host key for IP address 'xxx.xxx.xxx.xxx' to the list of known hosts.
# From bitbucket.org:owner/project
#  * [new branch]      master     -> origin/master
# You asked to pull from the remote 'origin', but did not specify
# a branch. Because this is not the default configured remote
# for your current branch, you must specify a branch on the command line.

上面列出了每个命令的输出,您可以看到初始存储库下载到project文件夹(这模拟了您的同事的存储库),然后当我重命名原点时,本地存储库中没有下载,将新原点添加为bitbucket url并转到git pull origin

更新:使用两个git版本进行检查

正如其他答案的评论中所提到的,有两个版本的git涉及 - git 1.9.4在同事机器上,git 2.1.4在本地。 我本地也有2.1.4,所以我还以这种方式获得1.9.4版本:

git clone git://git.kernel.org/pub/scm/git/git.git 
git checkout v1.9.4
make configure
./configure --prefix=/usr
make all
./git --version
# git version 1.9.4

现在我以这种方式修改了测试脚本:

# Change this to your repository url
BITBUCKET_URL=git@bitbucket.org:bosonz/gameofdata.git 

GIT194=./git/git

$GIT194 --version

$GIT194 clone $BITBUCKET_URL project
# Cloning into 'project'...
# ....
# (the rest is unchanged)

结果 - 仍然没有问题,从bitbucket下载仍然只进行一次。

答案 1 :(得分:1)

我相信重命名会更改为文件系统上的该分支存储的引用,因此可能会修改某些内容,以防止它在不下载的情况下链接对象。

您可以通过将origin暂时指向同事的回购,让它重新复制所需的数据,然后再将原点指向bitbucket来解决问题。首先

git remote set-url him:/home/foo/repo

然后git pull origin master希望通过LAN重新下载相同的1535对象。如果是,则可以再次使用set-url将其指回bitbucket

git remote set-rul <bitbucket-url>

此时git应该包含所有需要的对象,因为只有远程网址会发生变化,因此git pull应该提供already up-to-date