我正在学习git,并且我正在关注Git社区书籍。试图从我的Github存储库中提取文件:“拒绝合并不相关的历史”
之前(很久以前)我在Github上制作了一个公共仓库,附带一些文件。现在,我在当前的计算机上设置了一个本地Git存储库,并提交了一些文件。然后我添加了一个远程指向我Github的页面:
[[email protected] c]# git remote add learnc https://github.com/michaelklachko/Learning-C
这似乎是成功的:
[[email protected] c]# git remote show learnc
* remote learnc
Fetch URL: https://github.com/michaelklachko/Learning-C
Push URL: https://github.com/michaelklachko/Learning-C
HEAD branch: master
Remote branch:
master tracked
Local ref configured for 'git push':
master pushes to master (local out of date)
现在我想从我的GitHub库的文件下载到我的电脑。我这样做:
[[email protected] c]# git fetch learnc
[[email protected] c]# git merge learnc/master
warning: refname 'learnc/master' is ambiguous.
Already up-to-date.
但是,我没有看到我的本地目录中有任何新文件。我怎样才能得到它们?
我也试着这样做:
[[email protected] c]# git pull learnc master
From https://github.com/michaelklachko/Learning-C
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
顺便说一句,在当地我在主分支(没有其他分支机构):
[[email protected] c]# git status
On branch master
nothing to commit, working directory clean
当你设置你的本地仓库时,你克隆了你的Github仓库还是只是做了'git init'?在后一种情况下,这些回购是无关的(没有共同的提交),你不能合并它们(拉取取+合并)。 – Paul
我做了git init。那么我应该克隆我的Github仓库解决这个问题吗? – MichaelSB
你可以克隆你的Github仓库并继续使用它,但它仍然是单独的仓库。你想合并两个不相关的历史吗? – Paul