我正在學習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