gitignore 不会忽略 .idea 目录

gitignore does not ignore .idea directory

正在使用 phpStorm IDE 处理 Symfony2 项目,我已将几个文件添加到 git 忽略,但尽管已添加到 git 忽略,但总是出现一个文件... .我已经尝试了很多次,但它总是存在

.git忽略文件:

/app/config/parameters.yml
/bin/
/build/
/composer.phar
/vendor/
/web/bundles/
/app/bootstrap.php.cache
/app/cache/*
!app/cache/.gitkeep
/app/config/parameters.yml
/app/logs/*
!app/logs/.gitkeep
/app/phpunit.xml

#IDE metadata
**.idea/**

#Bash files
run.sh

git 不会忽略的是 .idea folder/files:

On branch develop
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/workspace.xml

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

知道为什么 git 不会像我在 gitignore... 中指定的那样忽略整个目录吗?

Git 从不忽略对跟踪文件的更改。由于它显示为已修改,因此该文件处于版本控制之下(idea/workspace.xml 文件通常不应如此),因此会跟踪对其所做的更改。从索引中删除它,使用 git rm --cached .idea/workspace.xml 完整保留您的本地副本并提交此更改。从那时起,它将被忽略,除非您强制将其添加回存储库或更改您的 gitignore 设置。

提交文件后,它将开始被跟踪
为了从此点删除文件,您必须将它们从存储库中删除。

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

Note

您仍然可以使用 assume-unchanged 标志忽略添加的文件

--[no-]assume-unchanged

When this flag is specified, the object names recorded for the paths are not updated.
Instead, this option sets/unsets the "assume unchanged" bit for the paths.

When the assume unchanged bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index.

If you want to change the working tree file, you need to unset the bit to tell Git.

Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.


解释如何从命令行执行,也可以通过 IDEA 完成。

# 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>
#idea folder
.idea/

这对我来说效果很好

我在 gitignore 文件中添加了它并为我工作

**/.idea