gitignore 以及如何忽略公共目录名称及其内容

发布于 2024-09-27 08:32:46 字数 636 浏览 0 评论 0原文

我一直在抓紧时间研究网络和有关 .gitignore 文件的各种文档。我对 Unix/Terminal(使用 Mac OS X)有点不懂,我一生都无法弄清楚如何忽略文件夹的内容(任何类型的内容,无论是文件还是另一个文件夹,不管有多深)。

我正在开发一个在一致的文件结构中生成图像文件的项目,但我们遇到了有关用户权限的合并冲突。我想忽略包含生成图像的文件夹,这样我们就可以避免任何进一步的麻烦,必须在每次拉取的基础上调整权限。我只是无法让 .gitignore 文件正常工作,所以我需要找出文件夹内容匹配的正确模式。我希望它足够通用,因为它可以轻松包含整个站点(因此,如果任何文件夹包含特定文件夹名称,它将忽略其内容)。

我尝试过:

# Images
resample/
resize/
min/

还有……

# Images
resample/*
resize/*
min/*

还有……

# Images
*/resample/*
*/resize/*
*/min/*

以及更多的组合,但结果并不令人满意。我也从来没有让 foldername/**/* 模式起作用。任何有关此问题的帮助将不胜感激!

I've been pulling out my hair researching the net and various docs about .gitignore files. I'm a bit of a n00b with Unix/Terminal (using Mac OS X) and I can't for the life of me figure out how to ignore a folder's contents (any kind of content, be it a file or another folder, no matter how deep it is).

I'm working on a project that generates image files within a consistent file structure, except we're getting merge conflicts regarding user permissions. I'd like to ignore the folders that contain the generated images so we can avoid any further hair-pulling having to adjust permissions on a per-pull basis. I'm just having trouble getting the .gitignore file to work, so I need to figure out the right pattern for folder's content matching. I want it to be general enough in that it can easily encompass the whole site (so if any folder contains a particular folder name, it will ignore its contents).

I've tried:

# Images
resample/
resize/
min/

And...

# Images
resample/*
resize/*
min/*

And...

# Images
*/resample/*
*/resize/*
*/min/*

And many more combinations with unsatisfactory results. I never got the foldername/**/* pattern to ever work either. Any help regarding this issue would be most appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

内心荒芜 2024-10-04 08:32:46

感谢之前发帖者的帮助。经过进一步研究,我发现了如何正确实现新的 .gitignore 规则。问题是之前图像被跟踪,所以我必须删除对 .git/index 文件中文件的引用,就像这样......

// Remove all tracked files from the index
// (doesn't remove the file, just the reference)
git rm -r --cached .

// Add all the files again
// (files and folders specified by .gitignore aren't added to the index)
git add .

// Commit to save changes
git commit -am "gitignore update"

Thanks to the previous posters for their help. After some further delving in, I discovered how to properly implement the new .gitignore rules. The problem was that previously the images were being tracked so I had to remove the reference to the files within the .git/index file, like so...

// Remove all tracked files from the index
// (doesn't remove the file, just the reference)
git rm -r --cached .

// Add all the files again
// (files and folders specified by .gitignore aren't added to the index)
git add .

// Commit to save changes
git commit -am "gitignore update"
瑶笙 2024-10-04 08:32:46

您正在寻找 gitignore

gitignore 文件指定 git 应忽略的有意未跟踪的文件。请注意,所有
gitignore 文件实际上只涉及 git 尚未跟踪的文件;

如果您的文件或文件夹位于存储库中,则必须将其从存储库中删除才能忽略。

还要注意模式中的大小写敏感性。

假设这些文件夹当前不受版本控制,您的第一个列表应该可以工作。

# Images
resample/
resize/
min/

You're looking for gitignore

A gitignore file specifies intentionally untracked files that git should ignore. Note that all the
gitignore files really concern only files that are not already tracked by git;

If your file or folder is in the repository it must be deleted from the repository for it to be ignorable.

Also watch out for case sensitivity in your patterns.

Your first list should work assuming those folders are not under version control currently.

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