Git - 创建一个.gitignore文件 [英] Git - Creating a .gitignore file

查看:103
本文介绍了Git - 创建一个.gitignore文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 .gitignore 文件,因此某些文件不会被签入存储库。有没有人有关于如何以及在何处放置此文件的指南?我已经尝试将它放在我的工作目录中,运行git status,它仍在继续处理我希望它忽略的文件。



我使用了 .gitignore 我找到的文件:

  ######### ########## 
#编译源码#
###################
* .com
* .class
* .dll
* .exe
* .pdb
* .dll.config
* .cache
* .suo
#包含dll,如果它们在NuGet包目录中
!/ packages / * / lib / *。dll
#包含dll,如果它们位于CommonReferences目录中
! * CommonReferences / *。dll
####################
#VS升级内容#
####### #############
UpgradeLog.XML
_UpgradeReport_Files /
###############
#目录#
###############
bin /
obj /
TestResults /
####### ############
#Web发布日志#
###################
*。 Publish.xml
#############
#Resharper#
#############
/ _ReSharper 。*
* .ReSharp呃。*
############
#软件包#
############
#最好是解压这些文件并提交原始源
#git有自己的内置压缩方法
* .7z
* .dmg
* .gz
* .iso
* .jar
* .rar
* .tar
* .zip
################### ###
#日志和数据库#
######################
* .log
* .sqlite
#操作系统生成的文件#
######################
.DS_Store?
ehthumbs.db
图标?
Thumbs.db


解决方案

放置.gitignore取决于文件是否只需要一个回购或所有回购就可以忽略。
对于一个仓库,将其放置在仓库的根目录中。



当您在现有仓库中创建.gitignore文件或添加已经存在的文件时在回购中,您必须确保从回购库中删除要被忽略的文件。



如果您在根目录中有test.dll,要做

  git rm --cached test.dll 
  git rm -r --cached。 
git add。
git commit -m开始使用.gitignore


I'm looking to create a .gitignore file so certain files are do not get checked in to the repository. Does anyone have a guide on how and where to place this file? I have tried placing it in my working directory, ran git status and it is still picking up on the files I would like it to ignore.

I used this .gitignore file I have found:

###################
# 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

解决方案

Placement of .gitignore depends if the files need to be ignored for just one repo or for all your repos. For one repo, place it in the root of your repo.

When you create a .gitignore file in an existing repo, or add files that were already in the repo, you have to make sure to remove the to-be-ignored files from the repo.

If you have a test.dll in the root, you have to do

git rm --cached test.dll

Now if you have a lot of files, like you said you can opt for the following option, remove everything from the cache, add it all back (the files in .gitignore will not be added) and commit everything again.

git rm -r --cached .
git add .
git commit -m "Start using .gitignore"

这篇关于Git - 创建一个.gitignore文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆