.gitignore not ignoring .idea path

只谈情不闲聊 提交于 2019-12-03 00:10:40

问题


What am I missing that needs to be done in order to get git to ignore my .idea/ path?

ctote@ubuntu:~/dev/1$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   .idea/.name
    modified:   .idea/misc.xml
    modified:   .idea/modules.xml
    modified:   .idea/vcs.xml
    modified:   .idea/workspace.xml
    modified:   src/Receiver.java
    modified:   test/1/agent/WindowsQueryHandlerTest.java

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    lib/
    mp1.iml

no changes added to commit (use "git add" and/or "git commit -a")

ctote@ubuntu:~/dev/1$ cat .gitignore
*.class

# Package Files #
*.war
*.ear

# IDEA config files
.idea/

回答1:


.gitignore only ignores newly added (untracked) files.

If you have files that have already been added to the repository, all their changes will be tracked as usual, even if they are matched by .gitignore rules.

To remove that folder from the repository (without deleting it from disk), do:

git rm --cached -r .idea



回答2:


add .idea/ to .gitignore file

run this commands in terminal to complete mission :)

git rm -rf .idea
git commit -m "delete .idea"
git push



回答3:


To remove the "fatal: pathspec '.idea' did not match any files" just use if the dir still returns as untracked:

git clean -f -d .idea




回答4:


For those of you getting fatal: pathspec '.idea' did not match any files with w0lf's answer:

You just have to include the full path to the .idea folder.

So first, do a git status, which should show you the path to .idea given where you currently are.

Then, include the path in the command w0lf suggested: git rm --cached -r example/path/to/.idea




回答5:


To Solve Error "fatal: pathspec '.idea' did not match any files" after entering above command,

  1. Check the path of your idea folder and its files.
  2. For this do git status. It will list all the files as usual. Check the path of idea folder files. Mine was at ../.idea/workspace.xml. Notice the ../.idea
  3. Modify the above suggested command in the accepted answer to git rm --cached -r ../.idea
  4. You will then see this rm '.idea/workspace.xml' and the files will be removed.



回答6:


If, after following steps from other answers, you still find that your instance of git running in bash or powershell just keeps on tracking the .idea/ folder, then try this!

I discovered that Jet Brains IDE's have their own .gitignore, and run their own instance of git that will override your .gitignore settings!

What I did to fix this was to navigate to /.idea/.gitignore, and change its contents to:

/**

so as to ignore everything in the folder.

The image below shows how you can navigate to the .gitignore file from within your Jetbrains IDE.



来源:https://stackoverflow.com/questions/32384473/gitignore-not-ignoring-idea-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!