首页 > 解决方案 > 如何防止 .idea/ 目录被推送到远程?

问题描述

新手到 git 工作流程。

我已经开始从事一个开源项目。我分叉了回购。

但是,当我将提交推送到远程分叉时,.idea/会在 GitHub 上生成一个目录。Github 回购。我的 gitignore 文件包含.idea/路径。

我已在此Remove a file from a Git repository./idea的帮助下删除了本地 git 存储库。但是,当我推送到远程时,目录仍然存在。.idea/

标签: gitandroid-studiogithubintellij-idea

解决方案


我的 gitignore 文件包含 .idea/ 路径。

一旦您提交文件,它将开始被跟踪。所以将它添加到您的 中是不够的.gitignore,您还必须将其从存储库中删除。

为了从此时删除文件,您必须从存储库中删除它们。

git rm --cached .idea/

此命令仅从暂存中删除文件,而不是从文件系统中删除,稍后添加到 .gitignore。

您现在需要做的是删除整个 .idea 文件夹,提交删除,将想法扩展名添加到您的 .gitignore 文件中。

# Remove the file from the repository
git rm --cached .idea/

# now update your gitignore file to ignore this folder
echo '.idea' >> .gitignore

# add the .gitignore file
git add .gitignore

git commit -m "Removed .idea files"
git push origin <branch>

推荐阅读