![git 忽略以提交的文件](https://i-blog.csdnimg.cn/blog_migrate/231ffb37760bba94b497640e8c65533e.png)
git 忽略以提交的文件
Git is used for a lot of different projects. These projects may provide different types of files. Some times some of those files should not be committed into the repository. For example, after running a python application pyc files are created as compiled python files. Committing them are unnecessary.
Git用于许多不同的项目。 这些项目可能提供不同类型的文件。 有时候,其中一些文件不应提交到存储库中。 例如,运行python应用程序后,将pyc文件创建为已编译的python文件。 提交它们是不必要的。
Git忽略文件 (Git Ignore File)
To ignore files the patterns should be defined in a file named .gitignore
file. .gitignore
file by default resides in the root of the repository but can be used in subdirectories too.
要忽略文件,应在名为.gitignore
文件中定义模式。 默认情况下, .gitignore
文件位于存储库的根目录中,但也可以在子目录中使用。
$ echo "*.pyc" > .gitignore
$ cat .gitignore
*.pyc
$ echo "*.tmp" >> .gitignore
$ cat .gitignore
*.pyc
*.tmp
*.pyc
means any file ends with pyc extension*.pyc
表示任何以pyc扩展名结尾的文件- Each line for one entry每行一个条目
$ cat .gitignore
*.pyc
#temp files
*.tmp
#
is used as comment and no effect on files those will be ignored#
用作注释,对那些将被忽略的文件没有影响
$ cat .gitignore
/build
/build
directory is completely ignored/build
目录被完全忽略
$ cat .gitignore
/build/*.out
All files in
/build
directory with extension.out
/build
目录中所有扩展名为.out
翻译自: https://www.poftut.com/git-ignore-files-prevent-commit/
git 忽略以提交的文件