android studio 卸载git,如何从Android Studio项目中删除Git? - git代码 - 源码查

这篇博客解答了如何从Android Studio项目中彻底移除Git,并重新开始的问题。首先,.git文件夹是隐藏的,可以手动删除或通过命令行工具在项目根目录下删除该文件夹来移除Git。此外,还提到了在不同操作系统中显示隐藏文件的方法。在删除.git文件夹后,需要重新初始化Git并开始新的版本控制。如果项目已上传到GitHub,强制推送时需谨慎,因为这将覆盖远程仓库的历史记录。
摘要由CSDN通过智能技术生成

问题

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?

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] )"...

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, you can't remove it using Android Studio (there isn't a button for removing Git from a project). In addition, .git is a hidden folder, meaning it is (well,) hidden.

Git is also not dependent on Android Studio in any way. All of the Git history is stored in the .git folder.

There are (at least) three options.

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

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.

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

Windows:

rd /s /q ".git"

On Linux/Mac, you might have to use sudo to remove it (depending on permissions).

Linux/Mac:

rm -rf .git

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).

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.

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值