我希望创建一个.gitignore
文件,以便某些文件不会被签入存储库。有没有人有关于如何以及在何处放置此文件的指南?我尝试将其放在我的工作目录中,运行 git 状态,它仍在拾取我希望它忽略的文件。
使用了我找到的这个.gitignore
文件:
###################
# compiled source #
###################
*.com
*.class
*.dll
*.exe
*.pdb
*.dll.config
*.cache
*.suo
# Include dlls if they’re in the NuGet packages directory
!/packages/*/lib/*.dll
# Include dlls if they're in the CommonReferences directory
!*CommonReferences/*.dll
####################
# VS Upgrade stuff #
####################
UpgradeLog.XML
_UpgradeReport_Files/
###############
# Directories #
###############
bin/
obj/
TestResults/
###################
# Web publish log #
###################
*.Publish.xml
#############
# Resharper #
#############
/_ReSharper.*
*.ReSharper.*
############
# Packages #
############
# it’s better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
######################
# Logs and databases #
######################
*.log
*.sqlite
# OS generated files #
######################
.DS_Store?
ehthumbs.db
Icon?
Thumbs.db
.gitignore 的位置取决于是只需要忽略一个存储库的文件,还是需要忽略所有存储库的文件。对于一个存储库,请将其放在存储库的根目录中。
在现有存储库中创建 .gitignore 文件或添加存储库中已有的文件时,必须确保从存储库中删除要忽略的文件。
如果你有一个测试.dll在根上,你必须做
git rm --cached test.dll
现在,如果您有很多文件,就像您说的那样,您可以选择以下选项,从缓存中删除所有内容,将其全部添加回来(不会添加 .gitignore 中的文件)并再次提交所有内容。
git rm -r --cached .
git add .
git commit -m "Start using .gitignore"
Git 看到它之前将.gitignore
添加到索引中。 即git add .gitignore
.
我参与过的项目,我在项目的根目录中有 .gitignore 文件,.git 目录将位于该目录。 确保文件已提交。
请注意,如果您已经提交了您尝试忽略的文件(即 Git 正在跟踪它们),则不能忽略它们。 您必须先取消跟踪它们。
https://help.github.com/articles/ignoring-files
从@thescientist发布的链接:
Git 允许您通过假设这些文件保持不变来忽略它们。这是通过运行
git update-index --assume-unchanged path/to/file.txt
命令。一旦将文件标记为这样,git 将完全忽略该文件的任何更改;它们在运行 Git Status 或 Git diff 时不会显示,也不会提交。