我在 GitLab(在瀏覽器中)創建了一個新的空白專案。我檢查了“使用自述檔案初始化存盤庫”框。但是打開它時,它說:“這個專案的存盤庫是空的。” 我假設我仍然需要初始化一個 README.md 檔案以便主分支存在?所以在我嘗試的命令列中(我使用的是 Windows 10):
git clone https://gitlab.com/url/myproject.git
cd myproject
git switch -c main
touch README.md
git add README.md
git commit -m "add README"
但它說:
C:\Users\me>git clone https://gitlab.com/ur/myproject.git
fatal: destination path 'myproject' already exists and is not an empty directory.
C:\Users\me>cd myproject
C:\Users\me\myproject>git switch -c main
fatal: A branch named 'main' already exists.
C:\Users\me\myproject>touch README.md
'touch' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\me\myproject>git add README.md
C:\Users\me\myproject>git commit -m "add README"
On branch main
Your branch is based on 'origin/main', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
nothing to commit, working tree clean
我的專案仍然是空的,我無法添加或推送任何內容。為什么?
編輯:如果我導航到專案并執行dir,我得到(我只洗掉了卷序列號):
C:\Users\me\myproject>dir
Volume in drive C has no label.
Volume Serial Number is ...
Directory of C:\Users\me\myproject
13.12.2021 09:29 <DIR> .
13.12.2021 09:29 <DIR> ..
13.12.2021 09:29 0 README.md
1 File(s) 0 bytes
2 Dir(s) 112.515.997.696 bytes free
uj5u.com熱心網友回復:
讓我們一一分解錯誤。
C:\Users\me>git clone https://gitlab.com/ur/myproject.git
fatal: destination path 'myproject' already exists and is not an empty directory.
該myproject檔案夾已存在 - 很可能您已經克隆了該專案,因此此處無需再執行任何操作。
C:\Users\me\myproject>git switch -c main
fatal: A branch named 'main' already exists.
你不能創建一個main分支,因為它已經存在——所以再次,這里沒有什么可做的。
C:\Users\me\myproject>touch README.md
'touch' is not recognized as an internal or external command,
operable program or batch file.
touch是 Windows 中不存在的 *nix 命令。一種選擇是使用 Git Bash 而不是 CMD,后者提供了一個touch可執行檔案。或者,您可以使用另一種方法在 Windows 中創建一個空檔案。
C:\Users\me\myproject>git add README.md
C:\Users\me\myproject>git commit -m "add README"
On branch main
Your branch is based on 'origin/main', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
nothing to commit, working tree clean
這兩個命令沒有失敗,只是因為README.md沒有創建檔案而什么也沒做。創建它后,您可以重復這兩個命令,它們應該會成功。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/380593.html
上一篇:提交大量檔案的訊息
