使用 GIT 忽略文件夹中文件的最佳实践
我只是在寻找一些关于使用 git 管理以下情况的最佳方法的建议。
我的项目有一个名为“照片”的文件夹,用户可以将图像上传到其中。
我有一个在本地运行的项目版本,并且我将图像添加到此文件夹中以进行测试。
当我推送到实时服务器时,我希望推送“照片”文件夹,但不推送其中的图像。此外,当用户将图像添加到实时服务器上的“照片”文件夹时,我希望 GIT 忽略它们。
我知道我需要使用 Git Ignore,但我不确定最好的方法是什么。
我应该将“照片”添加到 git 忽略文件中,然后在实时服务器上手动创建“照片”文件夹吗?
提前致谢。
I'm just looking for some advice on the best way to manage the following situation with git.
my project has a folder called "photos" that users can upload images to.
I have a version of the project running locally and I am adding images to this folder for testing purposes.
When I push to the live server I want the "photos" folder to get pushed but not the images within it. Also when users add images to the "photos" folder on the live server I want GIT to ignore them.
I know I need to use Git Ignore but I'm unsure what the best way to do this is.
Should I just add "photos" to the git ignore file and then manually create the "photos" folder on the live server?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Git 不支持空目录,但目录的标准做法是创建
.gitignore
文件在里面。*
条目导致 git 忽略目录内的任何内容(甚至是.gitignore
文件本身,因此需要add -f
来覆盖它)。Git does not support empty directories, but standard practice for a directory is to create a
.gitignore
file inside it. The*
entry causes git to ignore anything inside the directory (even the.gitignore
file itself, hence theadd -f
to override that).