git 目标路径已存在且不是空目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50361138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:16:43  来源:igfitidea点击:

destination path already exists and is not an empty directory

git

提问by flopga slays

I cloned a git repository but accidentally messed up. So I re-cloned and the message showed up:

我克隆了一个 git 存储库,但不小心搞砸了。所以我重新克隆并显示消息:

destination path already exists and is not an empty directory

目标路径已存在且不是空目录

I've tried deleting folders in my mac with the name of the destination path but it did not work.

我尝试使用目标路径的名称删除我的 mac 中的文件夹,但它没有用。

I'm very new to coding so all help would be appreciated.

我对编码很陌生,因此将不胜感激所有帮助。

回答by Sean Becker

Explanation

解释

This is pretty vague but I'll do what I can to help.

这很模糊,但我会尽我所能提供帮助。

First, while it may seem daunting at first, I suggest you learn how to do things from the command line (called terminal on OSX). This is a great way to make sure you're putting things where you really want to.

首先,虽然一开始看起来令人生畏,但我建议您学习如何从命令行(在 OSX 上称为终端)中进行操作。这是确保你把东西放在你真正想要的地方的好方法。

You should definitely google 'unix commands' to learn more, but here are a few important commands to help in this situation:

您绝对应该谷歌“unix 命令”以了解更多信息,但这里有一些重要的命令可以在这种情况下提供帮助:

ls- list all files and directories (folders) in current directory

ls- 列出当前目录中的所有文件和目录(文件夹)

cd <input directory here without these brackets>- change directory, or change the folder you're looking in

cd <input directory here without these brackets>- 更改目录,或更改您正在查找的文件夹

mkdir <input directory name without brackets>- Makes a new directory (be careful, you will have to cd into the directory after you make it)

mkdir <input directory name without brackets>- 创建一个新目录(小心,创建后必须cd进入该目录)

rm -r <input directory name without brackets>- Removes a directory and everything inside it

rm -r <input directory name without brackets>- 删除目录及其中的所有内容

git clone <link to repo without brackets>- Clones the repository into the directory you are currently browsing.

git clone <link to repo without brackets>- 将存储库克隆到您当前浏览的目录中。

Answer

回答

So, on my computer, I would run the following commands to create a directory (folder) called projects within my documents folder and clone a repo there.

因此,在我的计算机上,我将运行以下命令在我的文档文件夹中创建一个名为 projects 的目录(文件夹),并在那里克隆一个 repo。

  1. Open terminal
  2. cd documents(Not case sensitive on mac)
  3. mkdir projects
  4. cd projects
  5. git clone https://github.com/seanbecker15/wherecanifindit.git
  6. cd wherecanifindit(if I want to go into the directory)
  1. 打开终端
  2. cd documents(在 mac 上不区分大小写)
  3. mkdir projects
  4. cd projects
  5. git clone https://github.com/seanbecker15/wherecanifindit.git
  6. cd wherecanifindit(如果我想进入目录)

p.s. wherecanifindit is just the name of my git repository, not a command!

ps wherecanifindit 只是我的 git 存储库的名称,而不是命令!

回答by James Knott

This just means that the git clone copied the files down from github and placed them into a folder. If you try to do it again it will not let you because it can't clone into a folder that has files into it. So if you think the git clone did not complete properly, just delete the folder and do the git clone again. The clone creates a folder the same name as the git repo.

这只是意味着 git clone 从 github 复制文件并将它们放入一个文件夹中。如果您再次尝试这样做,它不会让您这样做,因为它无法克隆到包含文件的文件夹中。因此,如果您认为 git clone 没有正确完成,只需删除该文件夹并再次执行 git clone。克隆创建一个与 git repo 同名的文件夹。

回答by James Knott

If you got Destination path XXX already existsmeans the name of the project repository which you are trying to clone is already there in that current directory. So please cross-check and delete any existing one and try to clone it again

如果您得到Destination path XXX already exists意味着您尝试克隆的项目存储库的名称已经存在于该当前目录中。所以请交叉检查并删除任何现有的并尝试再次克隆它

回答by the775

An engineered way to solve this if you already have files you need to push to Github/Server:

如果您已经有需要推送到 Github/Server 的文件,则可以采用一种工程方法来解决此问题:

  1. In Github/Server where your repo will live:

    • Create empty Git Repo (Save <YourPathAndRepoName>)
    • $git init --bare
  2. Local Computer (Just put in any folder):

    • $touch .gitignore
    • (Add files you want to ignore in text editor to .gitignore)
    • $git clone <YourPathAndRepoName>

    • (This will create an empty folder with your Repo Name from Github/Server)

    • (Legitimately copy and paste all your files from wherever and paste them into this empty Repo)

    • $git add . && git commit -m "First Commit"

    • $git push origin master
  1. 在你的仓库所在的 Github/Server 中:

    • 创建空的 Git 存储库(保存<YourPathAndRepoName>
    • $git init --bare
  2. 本地计算机(只需放入任何文件夹):

    • $touch .gitignore
    • (将要在文本编辑器中忽略的文件添加到 .gitignore)
    • $git clone <YourPathAndRepoName>

    • (这将从 Github/Server 创建一个带有您的回购名称的空文件夹)

    • (从任何地方合法地复制和粘贴所有文件,然后将它们粘贴到这个空的 Repo 中)

    • $git add . && git commit -m "First Commit"

    • $git push origin master

回答by boly38

I got same issue while using cygwinto install nvm

我在使用cygwin安装nvm时遇到了同样的问题

In fact, the target directory where empty but the gitbinary used was the one from windows (and not gitfrom cygwin git package).

事实上,目标目录为空但使用的git二进制文件来自 windows(而不是git来自 cygwin git package)。

After installing cygwin git package, the git clonefrom nvminstall was ok!

安装后cygwin git packagegit clonenvm安装就OK了!