git 忽略以提交的文件_Git –忽略文件以防止提交

git 忽略以提交的文件

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

LEARN MORE  How To Remove Untracked Files In Git?
了解更多如何在Git中删除未跟踪的文件?

翻译自: https://www.poftut.com/git-ignore-files-prevent-commit/

git 忽略以提交的文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值