[英]How to get Git to clone into current directory
我正在做:
git clone ssh://user@host.com/home/user/private/repos/project_hub.git ./
我越來越:
致命:目標路徑“。” 已經存在並且不是空目錄。
我知道路徑。 已經存在。 我可以保證該目錄是空的。 (我在里面做 ls ,我什么也沒看到!)
為了將該項目克隆到當前目錄中,我在這里缺少什么?
只需在它旁邊放一個點
git clone git@github.com:user/my-project.git .
從git help clone
:
僅當目錄為空時才允許克隆到現有目錄。
因此,請確保目錄為空(使用ls -a
檢查),否則命令將失敗。
在所有情況下,以下內容可能並不完全等同於克隆,但對我有用:
git init .
git remote add -t \* -f origin <repository-url>
git checkout master
就我而言,這會生成一個.git/config
文件,該文件等同於我在克隆時得到的文件。
@Andrew 已經在這里清楚地回答了。 但是即使目錄不為空,這樣簡單也可以:
git init .
git remote add origin <repository-url>
git pull origin master
做
git clone https://user@bitbucket.org/user/projectname.git .
目錄必須為空
為確保您可以克隆存儲庫,請轉到任何臨時目錄並在那里克隆項目:
git clone ssh://user@host.com/home/user/private/repos/project_hub.git
這會將您的東西克隆到project_hub
目錄中。
克隆完成后,您可以將此目錄移動到任何您想要的位置:
mv project_hub /path/to/new/location
這是安全的,不需要任何神奇的東西。
git clone your-repo tmp && mv tmp/.git . && rm -rf tmp && git reset --hard
使用$(pwd)
指定絕對當前路徑對我有用。
git clone https://github.com/me/myproject.git $(pwd)
git版本: 2.21.0
根據票證描述,需要空目錄。
.
IE
git clone https://github.com/me/myproject.git .
git版本: 2.36.1
如果當前目錄為空,那么這將起作用:
git clone <repository> foo; mv foo/* foo/.git* .; rmdir foo
解決方案是使用dot
,所以:
rm -rf .* && git clone ssh://user@host.com/home/user/private/repos/project_hub.git .`
如果我們絕對確定目錄為空,則可以省略rm -rf .* &&
。
致謝:@James McLaughlin 評論
除了@StephaneDelcroix 的回答,在使用之前:
git clone git@github.com.user/my-project.git .
通過使用確保您當前的目錄為空
ls -a
我也有同樣的需要。 在我的例子中,我有一個標准的 web 文件夾,它是由 web 服務器安裝創建的。 出於此說明的目的,假設這是
/server/webroot
並且 webroot 包含其他標准文件和文件夾。 我的倉庫只有站點特定的文件(html、javascript、CFML 等)
我所要做的就是:
cd /server/webroot
git init
git pull [url to my repo.git]
您需要小心地在目標文件夾中執行 git init,因為如果您不這樣做,將會發生以下兩種情況之一:
致命:不是 git 存儲庫(或任何父目錄):.git
這不會干擾我的 webroot 文件夾中的任何“標准”文件,但我確實需要將它們添加到 .gitignore 文件中,以防止無意中將它們添加到后續提交中。
這似乎是一種“克隆”到非空目錄的簡單方法。 如果您不想要拉取創建的 .git 和 .gitignore 文件,只需在拉取后將其刪除即可。
進一步改進@phatblat 的答案:
git clone --no-checkout <repository> tmp \
&& mv tmp/.git . \
&& rmdir tmp \
&& git checkout master
作為一個班輪:
git clone --no-checkout <repository> tmp && mv tmp/.git . && rmdir tmp && git checkout master
我用它來克隆一個 repo 到當前目錄,該目錄不是空的。 不一定是干凈的生活,但它是在一個一次性碼頭集裝箱中:
git clone https://github.com/myself/myRepo.git temp
cp -r temp/* .
rm -rf temp
在這里,我使用cp -r
而不是mv
,因為它會復制隱藏的文件和目錄。 然后使用rm -rf
處理臨時目錄
改進@GoZoner 的回答:
git clone <repository> foo; shopt -s dotglob nullglob; mv foo/* .; rmdir foo
shopt 命令取自此 SO 答案,並將 Bash 上的“mv”命令的行為更改為包含點文件,您需要包含 .git 目錄和任何其他隱藏文件。
另請注意,只有在當前目錄 (.) 為空時才能保證按原樣工作,但只要克隆的 repo 中的文件與當前目錄中的文件不具有相同名稱,它就會工作。 如果您不關心當前目錄中的內容,可以在“mv”命令中添加 -f(強制)選項。
shopt -s dotglob
git clone ssh://user@host.com/home/user/private/repos/project_hub.git tmp && mv tmp/* . && rm -rf tmp
git clone ssh://user@host.com/home/user/private/repos/project_hub.git $(pwd)
使用.
在您的命令結束時,如下所示
git clone URL .
我看到這個:
fatal: destination path 'CouchPotatoServer' already exists and is not an empty directory.
在我的搜索中,我偶然發現:
https://couchpota.to/forum/viewtopic.php?t=3943
查找 Clinton.Hall 的條目......如果你嘗試這個(就像我一樣),你可能會得到access denied
的響應,這是我的第一個線索,所以最初的錯誤(對我來說)實際上是在逃避錯誤的根源問題。
在 Windows 中解決此問題:確保運行cmd
或git elevated
,然后運行:
git clone https://github.com/RuudBurger/CouchPotatoServer.git
以上是我的問題,簡單地提升對我有用。
只需刪除(或移動)給定目錄的內容,包括.git
目錄。
Android studio的Rebuild
等自動化工具將為您解決問題。
更多細節:
顯示給我的錯誤是jarresolver
git repo
顯示的路徑是temp\\jarresolver\\
我剛剛刪除了temp\\jarresolver\\
目錄的內容,包括隱藏的.git
目錄。
這就是全部,一切正常,無需克隆。
當我做Rebuild
,Android工作室克隆本身和構建成功。
所以我通過刪除根目錄中隱藏的 .git 文件夾來修復同樣的錯誤,然后在“git clone repo”中添加一個句點。 在我的根/dist 文件夾中。 這是在 vue-cli webpack 項目的上下文中。 所以其他人說的是對的,這通常意味着您在嘗試克隆到的文件夾或相關文件夾的父文件夾或根目錄中都有 git 跟蹤!
Windows
的解決方案是將存儲庫克隆到其他文件夾,然后復制並粘貼到原始位置,或者只是復制.git
不可見文件夾。
如果repo是私有的, 首先添加你的ssh密鑰使用=> git clone git@github.com:yourusername / yourrepo.git else use => git clone https://github.com/yourusername/yourrepo.git
刪除
rm -rf .*
可能會給您帶來麻煩或更多錯誤。
如果您有 /path/to/folder,並且想刪除其中的所有內容,但不是該文件夾,請運行:
rm -rf /路徑/到/文件夾/*
我已經多次看過這個問題了 - 我只想指出你目錄中的git pull
會起作用。
除非我在這里遺漏了一些東西 - 這對我有用。
通過mkdir filename
創建一個新的項目目錄,然后運行git clone xxxxx
命令,並將文件移動到上面,這很有用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.