致命错误:"/Users/username/Downloads/folder_name"在存储库外部 [英] Error in Git- fatal: '/Users/username/Downloads/folder_name' is outside repository

查看:108
本文介绍了致命错误:"/Users/username/Downloads/folder_name"在存储库外部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将新项目添加到git时,出现此错误.

When I am adding a new project to git, I am getting this error.

Error - fatal: '/Users/username/Downloads/folder_name' is outside repository

如何克服这个错误?我认为,我需要提供当前的工作目录.但是,不知道该怎么做.有人可以帮助我吗? 但是当我直接添加新文件时,它可以正常工作. 非常感谢您的帮助.谢谢.

How to get ride of this error? I think, I need to give the current working directory. But, don't know how to do that..Can anyone help me out of this? But when I add new file directly, it works fine.. Your help is highly appreciated..Thanks in advance.

推荐答案

Git无法跟踪存储库之外的文件,因此在执行操作时会跟踪

Git is not able to track files outside of the repository, and so when you're doing

git add /Users/dineshkumar/Documents/sampleios

Git从字面上告诉您:您要添加的路径位于您所在的初始化存储库之外.

Git tells you just that, literally: the path you're trying to add lies outside of the initialized repository you're in.

存储库"一词有点无聊,所以让我们说得更清楚些.

The term repository is a bit moot so let's make it more clear.

通常,您像这样使用Git:

Usually you work with Git like this:

$ mkdir project; cd project
$ git init
$ vim upload.php
...
$ git add upload.php
...
$ git commit

当您在目录(本例中为"project")中运行git init时,Git会在其中创建一个名为".git"的特殊子目录.其中包含实际的存储库数据(对象和配置)—然后将封闭的目录变成工作树.工作树包含您实际编辑并提交给Git的文件,以建立下一个提交.

When you run git init in a directory ("project" in our case) Git creates a special subdirectory named ".git" in it — which contains the actual repository data (objects and configuration) — and then turns the enclosing directory into a work tree. The work tree contains the files which you actually edit and submit to Git to build up the next commit.

此设计的关键优势在于,只有位于工作树中的文件才由Git管理.您不能从其他地方git add文件—仅在工作树中.因此,没有人调用具有完整路径的git add,因为这没有意义.

The crucial propety of this design is that only files located in the work tree are managed by Git. You can't git add a file from somewhere else — only from within the work tree. Consequently, no one calls git add with full paths because this has no sense.

我不确定您的困惑根源在哪里.如果您认为git add命令应该将文件/目录从某个地方复制到工作树中,那么您错了.如果您不了解工作树,并认为该存储库能够跟踪文件系统树中的任意文件,那么您又错了—如果确实如此,克隆将如何工作?

I'm not sure where your confusion is rooted. If you think that the git add command is supposed to copy a file/directory from somewhere into the work tree, you're wrong. If you were't aware of the work tree and thought that the repository is able to track arbitrary files on a filesystem tree, you're wrong again — how would cloning work if this was true?

您应该熟悉git add不是将添加文件到存储库中,而是将更改添加到所谓的文件中的想法.暂存区,从该暂存区进行下一次提交.添加当前未跟踪的文件只是此—的一种特殊情况.此添加只是整个文件的更改".

You should make yourself familiar with the idea that git add is not for adding files to the repository, it's rather for adding changes in files into the so-called staging area, from which the next commit is made. Adding a presently untracked file is just a special case of this — this addition is just a whole-file "change".

看看您的尝试,我可能会猜测您想将/Users/dineshkumar/Documents/sampleios转换为Git存储库.如果是这样,

Looking at your attempts I might make a guess that you want to turn /Users/dineshkumar/Documents/sampleios into a Git repository. If this is the case, do

$ cd /Users/dineshkumar/Documents/sampleios
$ git init
$ git add .
$ git commit

但是在您执行此操作之前,请这本书开始,因为您似乎缺乏最基本的知识Git知识.

But before you do that please start with the book as you seem to lack the most basic Git knowledge.

这篇关于致命错误:"/Users/username/Downloads/folder_name"在存储库外部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆