我不小心将.idea/目录提交到git中。这导致冲突的其他地方,我需要签出我的回购。我想知道如何从遥控器上删除这些文件?

我在本地仍然需要这些文件,因为Intellij IDE需要它们。我只是不想让他们出现在遥控器上。我已经添加了目录。idea/到我的。gitignore并提交并将此文件推到远程。这似乎没有影响,在我的结帐在我的另一台机器。我仍然得到错误消息:

error: The following untracked working tree files would be overwritten by checkout:
.idea/.name
.idea/compiler.xml
.idea/copyright/profiles_settings.xml
.idea/encodings.xml
.idea/misc.xml
.idea/modules.xml
.idea/scopes/scope_settings.xml
.idea/uiDesigner.xml
.idea/vcs.xml
.idea/workspace.xml

当前回答

为了避免这个问题再次出现,我发现有一个包含.idea的全局gitignore文件很有用,例如:

$ echo '.idea' >> ~/.gitignore_global
$ git config --global core.excludesfile ~/.gitignore_global

这种方法的另一个优点是不需要使用IDE的详细信息“污染”项目的.gitignore文件。另外,你也可以选择将.idea添加到项目的.gitignore中,这样项目的其他贡献者就不会遇到这个问题。

其他回答

为了避免这个问题再次出现,我发现有一个包含.idea的全局gitignore文件很有用,例如:

$ echo '.idea' >> ~/.gitignore_global
$ git config --global core.excludesfile ~/.gitignore_global

这种方法的另一个优点是不需要使用IDE的详细信息“污染”项目的.gitignore文件。另外,你也可以选择将.idea添加到项目的.gitignore中,这样项目的其他贡献者就不会遇到这个问题。

最好在Master分支上执行这个操作

编辑.gitignore文件。在其中添加下面的行。

.idea

从远程回收中删除。idea文件夹。使用以下命令。

Git rm -r——cached .idea

更多信息。参考:从Git存储库中删除文件而不实际删除它们

阶段。gitignore文件。使用以下命令

git add .gitignore

提交

git提交-m '删除。idea文件夹'

推送到远程

Git push origin master

将.idea目录添加到忽略文件列表中

首先,将它添加到.gitignore中,这样它就不会被你(或其他人)再次意外提交:

.idea

从存储库中删除它

其次,只从存储库中删除该目录,但不要在本地删除它。要做到这一点,请做下面列出的事情:

从Git存储库中删除文件,而不用从本地文件系统中删除它

将更改发送给其他人

第三,提交.gitignore文件并从存储库中删除.idea。然后把它推到遥控器上。

总结

整个过程是这样的:

$ echo '.idea' >> .gitignore
$ git rm -r --cached .idea
$ git add .gitignore
$ git commit -m '(some message stating you added .idea to ignored entries)'
$ git push

(你可以选择用git push some_remote替换最后一行,其中some_remote是你想要推送到的远程的名称)

如果你还没有推到git

git rm .idea/ -r --cached
git add -u .idea/
git commit -m "Removed the .idea folder"

如果“git rm .idea/ -r——cached”抛出一个错误“fatal: pathspec”。Idea '不匹配任何文件',并且已经推送到git上。Idea。

git push origin --delete remoteBranchName
git add . //Everything is up to date
git commit -m "Removed the .idea folder" //Nothing to commit
git push origin remoteBranchName

您可以从回购中删除它并提交更改。

git rm .idea/ -r --cached
git add -u .idea/
git commit -m "Removed the .idea folder"

之后,你可以把它推到远程,之后的每次签出/克隆都可以了。