如何从 Android Studio 项目中删除 Git? [英] How do I remove Git from Android Studio project?

查看:191
本文介绍了如何从 Android Studio 项目中删除 Git?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Android Studio 开发我的第一个项目,但无法正确配置 Git 和 GitHub.我想从我的项目中从 Git/Git 中完全删除我的项目并重新开始.我怎样才能做到这一点?另外,我的项目文件夹中没有 .git 文件夹,那么我的 git 文件在本地存储在哪里,我如何完全重新开始使用 Git 和 GitHub?

I'm developing my first project with Android Studio and can't quite get Git and GitHub configured properly. I'd like to completely remove my project from Git/Git from my project and start fresh. How can I do this? Also, there is no .git folder in my project folder, so where are my git files stored locally and how can I completely start over with Git and GitHub?

我在设置 -> 版本控制中将 VCS 设置为无",但我认为这不会删除 Git.该目录显示为未注册的根".我还想知道在此视图中显示多个目录是否正常?有时我有一些目录,目前我有我的项目目录和未注册的根应用程序([我的应用程序目录])"...

I've set VCS to 'None' in Settings -> Version Control, but I don't think this removes Git. The directory shows as "Unregistered roots". I was also wondering if it is normal to have several directories showing in this view? At times I've had and some directory, and at the moment I have my project directory and as Unregistered root "app ( [my app directory] )"...

有一次我设法将东西推送到 GitHub,但只有我的一些项目文件.我在初始提交后添加到项目中的其他人显示为未版本化,我添加了它们并尝试提交和推送,但不能.此外,每次我构建我的项目时,他们都会回到未版本化.这就是为什么我想完全重新开始

At one point I managed to push stuff onto GitHub, but only some of my project files. Others, which I added to the project after the initial commit, showed up as unversioned, I added them and tried to commit and push, but couldn't. Also, they went back to unversioned every time I built my project. This is why I'd like to completely start over

推荐答案

AFAIK,您无法使用 Android Studio 删除它(没有用于从项目中删除 Git 的按钮).(更新:现在不正确,但此答案的其余部分仍然正确且有效,因为 Git 仍然以这种方式工作答案依赖).

AFAIK, you can't remove it using Android Studio (there isn't a button for removing Git from a project). (Upd.: now incorrect, but the rest of this answer is still correct and functional, because Git still works the way this answer relies on).

此外,.git 是一个隐藏文件夹,这意味着它是隐藏的.ls 需要 -a 来显示,大多数文件浏览器不显示文件夹.

In addition, .git is a hidden folder, meaning it's, well, hidden. ls needs -a to show it, and most file explorers don't show the folder.

Git 也不以任何方式依赖 Android Studio.所有 Git 历史记录都存储在 .git 文件夹中,无论有没有 Android Studio 都可以使用.

Git is also not dependent on Android Studio in any way. All of the Git history is stored in the .git folder, and is usable with or without Android Studio.

有(至少)三个选项.

第一种移除它的方法相当简单.因此,当您进入项目根目录时,只需将 /.git 附加到路径即可.

The first method to removing it is fairly simple. So when you go into your project root, simply append /.git to the path.

因此,如果您的项目根目录是 D:/files/SomeProject,请附加 Git 文件夹,使实际路径变为 D:/files/SomeProject/.git 并删除里面的所有文件和文件夹.

So if your project root is D:/files/SomeProject, append the Git folder so the actual path becomes D:/files/SomeProject/.git and delete all the files and folders in there.

或者,您也可以使用命令提示符删除它(注意,这假设您先 cd 进入根目录):

Alternatively, you can also use command prompt to delete it (note that this assumes you cd into the root dir first):

视窗:

rd /s /q ".git"

Linux/Mac:

rm -rf .git

当然还有显示隐藏文件夹的选项,但这会在任何地方显示它们.至少对于 Windows (10),搜索 folder(如果您的计算机不使用英语,也可以使用适用的语言)并选择显示隐藏的文件和文件夹".向下滚动,直到找到 隐藏的文件和文件夹,然后选择 show.其他操作系统有不同的方式,其中大部分可能在互联网上的某个地方都有介绍(也可能是不同的 Stack Exchange).

And there's of course the option to show hidden folders, but this shows them everywhere. At least for Windows (10), search for folder (alternatively in an applicable language if your computer doesn't use English) and select "Show hidden files and folders". Scroll down until you find Hidden files and folders and select show. Other operating systems have different ways, most of which are likely covered somewhere on the internet (possibly a different Stack Exchange as well).

无论您采用哪种方式,现在您只需执行 git init 并重新启动它.所有以前的历史记录都将消失,活动树将是左边的,因此请确保您在正确的分支上.当您删除 .git 文件夹时,如果不从远程重新拉取,就无法恢复历史记录,这假设您拥有/使用了一个.

No matter which way you do it, now you just do git init and you've restarted it. All previous history will be gone, and the active tree will be the one left, so make sure you're on the right branch. When you delete the .git folder, there's no way to recover the history without re-pulling from a remote, and this assumes you have/use one.

请注意,如果您的项目已经上传到 GitHub,则必须使用强制标志 (-f) 进行推送.否则它只会拒绝推送.非常小心地使用-f标志;它会给在 repo 上工作的任何其他人带来问题(尽管这只是一个真正的问题,如果有其他人),它会覆盖存储在 GitHub 上的当前版本的 repo,或者你推送到的任何其他远程,这通常无法恢复.

Note that if your project is already uploaded to GitHub, you have to use the force flag (-f) for the push. Otherwise it'll just reject the push. Use the -f flag extremely carefully; it will cause problems for anyone else working on the repo (though this is only really a concern if there are others), and it will overwrite the current version of the repo stored on GitHub, or in any other remote you push to, and this is usually unrecoverable.

这篇关于如何从 Android Studio 项目中删除 Git?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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