Git:忽略跟踪的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10755655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: Ignore tracked files
提问by haymansfield
I have some tracked files in a repository which are automatically modified when building the code. I don't want to untrack them, I just don't want them to appear as modified and I don't want them to be staged when I git add.
我在存储库中有一些跟踪文件,这些文件在构建代码时会自动修改。我不想取消跟踪它们,我只是不希望它们显示为已修改,并且我不希望它们在我 git add 时被暂存。
Is this possible?
这可能吗?
回答by Nick Veys
Sure.
当然。
git update-index --assume-unchanged [<file> ...]
To undo and start tracking again:
要撤消并再次开始跟踪:
git update-index --no-assume-unchanged [<file> ...]
回答by koct9i
An another solution using git attributes and %f in filter command:
在过滤器命令中使用 git 属性和 %f 的另一种解决方案:
git config filter.orig.clean "cat %f.orig"
cp filename filename.orig
echo "filename filter=orig" >> .git/info/attributes
echo "filename.orig" >> .git/info/exclude
回答by rogerdpack
Another approach (from a now deleted answer by Seth Robertson, but I found it helpful so resurrecting it) is to maintain a "tracked" template file, then have local untracked version of it, ex: "config.sample.ini" or "config.ini.template" see https://gist.github.com/canton7/1423106for a full example.
另一种方法(来自 Seth Robertson 现已删除的答案,但我发现它很有帮助,因此重新启动它)是维护一个“跟踪”模板文件,然后使用它的本地未跟踪版本,例如:“config.sample.ini”或“ config.ini.template"完整示例见https://gist.github.com/canton7/1423106。
Then there won't be any concerns if the file is changed within git, etc. and you can use .gitignore (finally) on the local untracked files.
然后,如果文件在 git 等中更改,则不会有任何问题,并且您可以在本地未跟踪的文件上使用 .gitignore(最终)。