git status:如何忽略一些更改
有没有办法让 git status 忽略文件中的某些更改?
背景
我的存储库中有一些自动生成的文件(是的,我知道通常不建议这样做,但我无权更改它)。每当我构建树时,这些自动生成的文件都会更新其中的状态信息(谁生成了它们,时间戳等)。
当我说 git status
时,我希望它对这些生成的文件运行一个过滤器,以去除这些瞬态状态信息。我只希望它出现在 git 输出的 “已更改但未更新:”
部分(如果有其他实际更改)。
使用 中找到的 .gitattributes
方法https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes,我能够使用 git diff
忽略这些状态行更改简单的 egrep
过滤器。我想获取 git status 来使用 textconv
过滤器(或类似的东西)。
如果合并不受任何此过滤的影响,我会更喜欢它。
Is there a way to have git status
ignore certain changes within a file?
Background
I have some files in my repository that are auto-generated (yes, I know that's typically not recommended, but I have no power to change this). Whenever I build my tree, these auto-generated files have status information updated in them (who generated them, a timestamp, etc.).
When I say git status
, I'd like it to run a filter on these generated files that strips out this transient status information. I only want it to show up in the "Changed but not updated:"
section of git's output if there are other, real changes.
Using the .gitattributes
approach found at https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes, I am able to get git diff
to ignore these status line changes using a simple egrep
filter. I'd like to get git status
to also use textconv
filters (or something equivalent).
I'd prefer it if merges aren't affected by any of this filtering.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以使用过滤器对 git 隐藏您的更改。指定“clean”过滤器,它将“清理”不必要的更改(将 Git 的文件版本提供给 Git),因此它不会看到更改(但它仍然可以在“git status”中列出文件)。
详细信息:更好的制作方法Git 对我的更改视而不见
另请参阅此问题的其他答案,他们也关于忽略更改。
You can also use filters to hide your changes from git. Specify "clean" filter that will "clean" unnecessary changes (feed Git's version of file to Git), so it will not see the change (but it still can list the file in "git status").
Details: Better way of making Git to turn a blind eye on my changes
Also see other answers to this question, they also about ignoring changes.
一个简单的解决方案是,在您想要忽略更改的文件或路径上运行以下命令:
如果您想再次开始跟踪更改,请运行以下命令:
您必须记住在发生更改时再次开始跟踪你想要承诺。
One easy solution is, run the following command on the file or path you want to ignore the changes of:
If you wanna start tracking changes again run the following command:
you will have to remember to start the tracking again when there is a change that you want to commit.
我想我应该报告我一直在使用的两种解决方法:
I thought I'd report back on the two workarounds that I've been using:
git checkout origin ...
as part of the build, for any generated files that had no semantic changes.