如何使用.gitignore仅跟踪特定文件? [英] How do I track only specific files using .gitignore?

查看:219
本文介绍了如何使用.gitignore仅跟踪特定文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该在我的Git存储库的.gitignore中放入什么内容,以排除其中的所有文件和目录(除了).例如,如果我在一个仓库中有大量文件和目录,只想让Git跟踪fileX.fileYdirectoryZ,但完全忽略其他所有内容,那么我的.gitignore中应该有什么?

What should I put in my Git repository's .gitignore to exclude all files and directories there except specific ones. For example if I have a large number of files and directories in a repo, and just want Git to track fileX, .fileY, and directoryZ, but completely ignore everything else, what should be in my .gitignore?

推荐答案

您应该忽略内容;但不包括文件夹.
这样您就可以排除文件.

You should ignore content; but exclude folders.
That allows you to exclude files.

/**
!/**/
!fileX

那是因为:

如果排除了该文件的父目录,则无法重新包含该文件.

通过 git checkignore -v 检查.gitignore的效果>

Check the effect of a .gitignore with git checkignore -v

git check-ignore -v -- afile

这篇关于如何使用.gitignore仅跟踪特定文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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