Git:如何防止提交仅用于调试目的而修改的文件? [英] Git: How to prevent committing files that were modified just for debugging purposes?

查看:102
本文介绍了Git:如何防止提交仅用于调试目的而修改的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很多时候,我喜欢修改一些代码行,以便更容易调试,但我实际上并不想提交它们。例如,我会通过注释掉一些代码行来禁用一些烦人的功能(比如广告),或者我将日志级别和过滤器设置为仅关注我所关注的那些,或者我会强制条件为真只是我想要运行的代码块实际上一直运行。

在Perforce中,我会为这些文件创建一个更改列表并将其标记为不要提交!。 Git中的这个相当于什么?分支无法正常工作,因为这些只进行调试的修改需要与我目前正在进行的其他更改一起存在。 解决方案

谢谢所有的答案。我最终做的是在git中写一个预先提交的钩子,在每个文件中检查字符串不提交(以及其他变体)。如果是这样,那么提交失败了,我必须在提交之前编辑这些行。这是因为调试代码应该以每行为基础来处理,而不是按文件处理,因为某些文件同时具有调试更改和实际更改以提交。 (我的旧解决方案与perforce没有解决这个问题)。


A lot of times, I like to modify some lines of code in order to make debugging easier, but I don't actually want to commit them. For instance, I'll disable some annoying features (like ads) by commenting out some lines of code, or I'll set the log levels and filters to only the ones I care about, or I'll force a conditional to be true just so the block of code I want to run actually runs all the time.

In Perforce, I would have created a "changelist" for these files and labeled it as "DON'T COMMIT!". What would be the equivalent of this in Git? A branch doesn't work because these debug-only modifications need to exist with other changes I'm currently making.

解决方案

Thanks all for the answers. What I ended up doing is writing a pre-commit hook in git that checks for the string "dont commit" (and other variations) in each of the files. If it does, then the commit fails, and I'll have to edit those lines before committing. This is because debug code should be treated on a per-line basis, not per-file, because some files have both debug changes and real changes to be committed. (my old solution with perforce did not address this issue).

这篇关于Git:如何防止提交仅用于调试目的而修改的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆