【问题标题】:What's the equivalent of git clone, using git init, git remote add, git fetch etc.?git clone 的等价物是什么,使用 git init、git remote add、git fetch 等?
【发布时间】:2019-02-21 15:47:11
【问题描述】:

目前I cannot clone repositories from a Bitbucket server,我发现我仍然可以执行一系列 git init、git remote add 等操作来获取我计算机上的存储库。 我想确保我完全产生了相当于“克隆”的东西。 以下是正确的吗?

git init
git remote add origin -m master https://www.myserver.com/bitbucket/scm/proj/repo.git
# need to do git fetch twice, otherwise for some reason git branch -r 
# returns "warning: ignoring broken ref refs/remotes/origin/HEAD"
git fetch
git fetch
git branch -r
git checkout --track origin/master
git checkout --track origin/develop
git checkout --track origin/feature/myfeature
# (etc.. for all the branches I need to work with)

我也不确定 git remote 中的标志 -m 是否需要或可能有害。

@jthill 建议的一些调试信息:

存储库 1

git ls-remote --symref origin HEAD
ref: refs/heads/master  HEAD
842163b275ade3ec317543ed3a645f537d719766        HEAD

存储库 2

git ls-remote --symref origin HEAD
ref: refs/heads/master  HEAD
1a1044eef2d46a292305dfc10cf076a4cf1e9933        HEAD

【问题讨论】:

    标签: git bitbucket git-clone bitbucket-server


    【解决方案1】:

    就是这样。克隆是初始化、远程添加和获取部分,之后您可以例如git checkout master 甚至在创建本地 ref 之前,git 就会设置它并自动跟踪远程,因为该序列非常常见。 -m 只是绕过了 bitbucket 存储库作为其自己的主分支的内容,并告诉本地 git 你想要什么,如果 master 是你想要的,那就是你想要的。

    所以-m“应该”,据我所知,避免与源的HEAD 发生任何错误配置,第二次获取“不应该”是必要的。如果您将git ls-remote --symref origin HEAD 的结果包含在内,则可能可以确定导致问题的原因,但我认为没有什么意义,您有一个解决方法。

    【讨论】:

    • 添加了有关问题的信息。感谢您的回答。
    • 好的,这里有很多干扰,我查看了您的另一个问题,您要克隆到的文件系统有些问题。您描述的症状,Git 似乎在克隆,完全正常的进度消息,当您在运行时 ls 显示 repo,然后在它完成后 repo 消失,这是荒谬的。这不是 Git 对你做的,这是一些自动文件系统管理工具,它决定出于何种原因移动或删除你放在那里的内容。
    猜你喜欢
    • 2017-05-30
    • 2013-12-05
    • 2020-05-16
    • 2011-06-18
    • 2011-08-14
    • 2021-08-26
    • 1970-01-01
    • 2015-07-20
    • 1970-01-01
    相关资源
    最近更新 更多