简体   繁体   English

如何取消注册目录为Git root?

[英]How do I unregister a directory as Git root?

I tried to push the project using git bash but I'd trouble understanding bunch of errors. 我试图使用git bash推送项目,但我很难理解一堆错误。 I deleted the hidden .git file from project folder. 我从项目文件夹中删除了隐藏的.git文件。 Now Android Studio is showing this error message: 现在Android Studio显示此错误消息:

Invalid VCS root mapping The directory is registered as a Git root, but no Git repositories were found there. 无效的VCS根映射目录注册为Git根目录,但没有找到Git存储库。

I want to git push directly from the Android Studio now. 我想直接从Android Studio直接推送。

You need to recreate you git repo again somehow. 你需要以某种方式再次重新创建git repo。 That hidden .git folder (no, it's not a file) is your git database. 那个隐藏的.git文件夹(不,它不是文件)是你的git数据库。 That's how git works. 这就是git的工作方式。 There's not server that maintains the state of you repo. 没有服务器可以维护您的回购状态。 Git is purely a disk based repository. Git纯粹是一个基于磁盘的存储库。

Installing new tools (like git bash or IntelliJ or SourceTree) don't create multiple different git databases for the same project. 安装新工具(如git bash或IntelliJ或SourceTree)不会为同一项目创建多个不同的git数据库。 That .git folder is the only database shared by all git related tools. .git文件夹是所有git相关工具共享的唯一数据库。

You have several options: 你有几个选择:

  1. You mentioned "push" so I'm going to assume there is a remote repository that you got your code from. 你提到了“推”,所以我假设有一个远程存储库,你可以从中获取代码。 If so you can just clone the repo again. 如果是这样,你可以再次克隆回购。

    If you want to save your current working files and try to push them again then you can clone to another directory and then copy all your files to the new repo. 如果要保存当前工作文件并尝试再次推送它们,则可以克隆到另一个目录,然后将所有文件复制到新的存储库。 Git will notice the differences and you can then commit your files. Git会注意到差异,然后您可以提交文件。 You will lose your commit history but at least you will still have your latest changes. 您将丢失提交历史记录,但至少您仍将获得最新更改。

  2. Alternatively, you can clone to another directory and then move that .git folder to your current project. 或者,您可以克隆到另一个目录,然后将该.git文件夹移动到当前项目。 Git will not know that you moved that .git folder because from git's point of view that .git repository have suddenly gained a lot of uncommitted files. Git不会知道你移动了.git文件夹,因为从git的角度来看.git存储库突然获得了很多未提交的文件。

  3. If there is no remote repo or if you've just created a new empty remote repo (for example on github) then I'm sorry you've lost your entire commit history. 如果没有远程仓库或者您刚刚创建了一个新的空远程仓库(例如在github上),那么我很抱歉您丢失了整个提交历史记录。 Your only option is to start fresh with a git init 你唯一的选择是使用git init重新开始

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM