使用 GIT 忽略文件夹中文件的最佳实践

发布于 2024-10-10 17:17:56 字数 318 浏览 0 评论 0原文

我只是在寻找一些关于使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

杀手六號 2024-10-17 17:17:56
echo '*' > photos/.gitignore
git add -f photos/.gitignore

Git 不支持空目录,但目录的标准做法是创建 .gitignore文件在里面。 * 条目导致 git 忽略目录内的任何内容(甚至是 .gitignore 文件本身,因此需要 add -f 来覆盖它)。

echo '*' > photos/.gitignore
git add -f photos/.gitignore

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 the add -f to override that).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文