git gitignore 不会忽略 .idea 目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36839838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gitignore does not ignore .idea directory
提问by John
Working on a Symfony2 project using phpStorm IDE, I have added couple of files to git ignore but one file despite being added to git ignore is always appearing....I have tried multiple times but its always there
在使用 phpStorm IDE 处理 Symfony2 项目时,我向 git ignore 添加了几个文件,但尽管已添加到 git ignore 一个文件总是出现......我已经尝试了多次,但它总是在那里
.gitignore file:
.gitignore 文件:
/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
And it is the .idea folder/files that git just will not ignore:
这是 .idea 文件夹/文件,git 不会忽略:
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")
Any idea why git will just not ignore the whole directory like i have specyfied in gitignore...?
知道为什么 git 不会像我在 gitignore 中指定的那样忽略整个目录......?
回答by Vampire
Git never ignores changes to tracked files. As it appears as modified, the file is under version control (the idea/workspace.xml file usually should not be) and thus changes to it are tracked. Delete it from the index, leaving your local copy intact with git rm --cached .idea/workspace.xml
and commit this change. From then on it will be ignored unless you force-add it back to the repository or change your gitignore settings.
Git 从不忽略对跟踪文件的更改。当它显示为已修改时,该文件处于版本控制之下(idea/workspace.xml 文件通常不应该),因此会跟踪对其的更改。从索引中删除它,保持本地副本完好无损git rm --cached .idea/workspace.xml
并提交此更改。从那时起,除非您将其强制添加回存储库或更改 gitignore 设置,否则它将被忽略。
回答by CodeWizard
Once you commit the file it will begin to be tracked.
In order to remove the file from this point you have to remove them from the repository.
一旦您提交文件,它将开始被跟踪。
为了从此时删除文件,您必须从存储库中删除它们。
What you need to do now is to delete the entire .idea
folder, commit the deletion, add the idea
extension to your .gitignore
file.
您现在需要做的是删除整个.idea
文件夹,提交删除,将idea
扩展名添加到您的.gitignore
文件中。
Note
Note
You can still ignore added files with the assume-unchanged
flag
您仍然可以使用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.
--[no-]assume-unchanged
指定此标志时,不会更新为路径记录的对象名称。
相反,此选项设置/取消设置路径的“假设不变”位。当该
assume unchanged
位打开时,用户承诺不更改文件并允许 Git 假设工作树文件与索引中记录的内容相匹配。如果要更改工作树文件,则需要取消设置该位以告诉 Git。
如果 Git 需要修改索引中的此文件,例如在合并提交时,Git 将失败(优雅地);因此,如果假定未跟踪的文件在上游发生更改,您将需要手动处理这种情况。
Explaining how to do from command line, can be done via IDEA as well.
解释如何从命令行完成,也可以通过 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>
回答by Faheem
#idea folder
.idea/
This worked fine for me
这对我来说很好用