我需要在我的.gitignore文件中添加一些规则。但是,我在项目文件夹中找不到它。它不是由Xcode自动创建的吗?如果没有,什么命令允许我创建一个?


当前回答

窗户

文件名:“。gitignore”, 保存为类型:所有文件(.)

其他回答

非常简单(有时):只需将以下内容添加到您首选的命令行界面(GNU Bash, Git Bash等)

touch .gitignore

正如War在评论中指出的那样,只要你提供完整的路径,触摸在Windows上也可以工作。这可能也解释了为什么它对Windows上的一些用户不起作用:在默认情况下,触摸命令似乎不在某些Windows版本的$PATH中。

C:\> "c:\program files (x86)\git\bin\touch.exe" .gitignore

注意:路径可能不同,取决于您的安装和安装路径。

http://gitignore.io是一个开源实用程序,可以帮助您为项目创建有用的.gitignore文件。还有一个可以通过gi命令访问的命令行API: http://gitignore.io/cli

为OS X安装gi命令: $回声”功能gi () {curl http://gitignore.io/api /\$@ ;}" >> ~/.Bash_profile && source ~/.bash_profile 查看.gitignore文件内容(输出:http://gitignore.io/api/xcode,osx): $ gi xcode,osx 如果您想将结果附加到一个新的.gitignore文件中,那么您应该在终端上看到输出。 $ gi xcode,osx >> .gitignore

您可以在Windows PowerShell中输入new-item .gitignore。

要创建一个.gitignore文件,你只需要创建一个.txt文件并更改扩展名,如下所示:

然后你必须改变名称,在cmd上写以下一行:

 rename git.txt .gitignore

其中git.txt是刚刚创建的文件的名称。

然后,您可以打开该文件并将不想添加到存储库中的所有文件写入。例如,我的是这样的:

# OS junk files
[Tt]humbs.db
*.DS_Store

# Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.pyc
*.xml
ipch/
obj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad

# Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*

# Project files
[Bb]uild/

# Subversion files
.svn

# Office Temp Files
~$*

一旦有了这个,就需要将它添加到Git存储库中。您必须将文件保存在存储库所在的位置。

然后在你的Git Bash中,你必须写下面这行:

如果存储库已经存在,您必须执行以下操作:

Git rm -r——cached。 Git添加。 Git commit -m”。Gitignore现在正在工作"

如果第2步不起作用,那么您应该编写想要添加的文件的整个路由。

创建一个.gitignore文件,包含所有你不想提交的文件和目录。

例子:

#################
## Eclipse
#################

*.pydevproject
.project
.metadata
.gradle
bin/
tmp/
target/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath


#################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml
*.pubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings