如何在 Git 中更改当前工作目录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19908615/
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-19 09:20:53  来源:igfitidea点击:

How to Change the current working Directory in Git?

gitdirectorybranchclone

提问by Dinesh Kumar

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

当我向存储库添加新项目时,出现此错误。

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

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.

我想,我需要给出当前的工作目录。但是,不知道该怎么做..谁能帮我解决这个问题?但是当我直接添加新文件时,它工作正常..非常感谢您的帮助..提前致谢。

I got everything fine..But if I refresh the page, it remains the same... https://github.com/dinesh-prodapt/myandroid.git

我一切都很好..但如果我刷新页面,它保持不变...... https://github.com/dinesh-prodapt/myandroid.git

That's why confused.. Here is what I am getting..

这就是为什么困惑..这就是我得到的..

Dinesh-iMac:~ dineshkumar$ git remote add origin [email protected]:dinesh-prodapt/myandroid.git
    fatal: remote origin already exists.
    Dinesh-iMac:~ dineshkumar$ git push -u origin master
    Counting objects: 3, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (2/2), 280 bytes | 0 bytes/s, done.
    Total 2 (delta 0), reused 0 (delta 0)
    To [email protected]:dinesh-prodapt/dinesh.git
       c6537f0..433adae  master -> master
    Branch master set up to track remote branch master from origin.
    Dinesh-iMac:~ dineshkumar$ git remote add origin [email protected]:dinesh-prodapt/myandroid.git
    fatal: remote origin already exists.
    Dinesh-iMac:~ dineshkumar$ git push -u origin master
    Branch master set up to track remote branch master from origin.
    Everything up-to-date

回答by exussum

you cant add a file to git using git addthat it outside of the folder.

您不能git add在文件夹外使用该文件将文件添加到 git 。

for example

例如

/Users/username/dir1   

Contains the .git folder (ie the git root)

包含 .git 文件夹(即 git root)

you can only add folders and files below that

您只能在其下方添加文件夹和文件

such as

/Users/username/dir1/images
/Users/username/dir1/src
/Users/username/dir1/dir2

But not

但不是

/Users/username/dir2
/Users/username/Desktop 

because they are outside of what git knows about

因为它们超出了 git 所知道的范围

you need to move the file (or copy) with the mv or cp commands to dir1 and then use git add

您需要使用 mv 或 cp 命令将文件(或复制)移动到 dir1,然后使用 git add

to the second problem (which you should really create a new question for)

到第二个问题(你真的应该为其创建一个新问题)

git remote origin exists already so call it something else or remove your exiting origin

git remote origin 已经存在所以称它为别的东西或删除你现有的 origin

git remote add github [email protected]:dinesh-prodapt/myandroid.git
git push -u github master