我在 github 上有一个我正在使用的 repo,我经常对以“# TODO:
”开头的 .py
文件发表评论,以保留要做的事情的个人笔记。
# TODO: do this <code>
我显然不希望将其提交。
我希望 GitHub 在我要提交文件时搜索所有文件,而不包括以 # TODO:
开头的行
Git 已经这样做了吗?我知道像 perforce 这样的某些版本控制已经具有此功能。
有什么想法吗?
最佳答案
I want GitHub to search all the files when I am about to commit them and not include lines that start with
# TODO:
GitHub(服务器端)不会那样做。
但是您可以在本地存储库中注册一个 content filter driver 它将在 git commit
( like a sed '/^# TODO:/ d'
) 上为您完成。
(图片显示在“Customizing Git - Git Attributes”中,来自“Pro Git book”)
A 'clean
' filter可以过滤掉那些行(我不会讨论你是否应该保留它们),并且该过滤器将自动应用于 git commit。
这显然会删除所有 TODO
,包括其他人留下的,因此请小心处理:技术上是可能的,但您必须确定是否在您的情况下需要/有用。
2016 年 2 月更新:使用 git 2.8,即使您已经定义了 git 内容过滤器,您也可以在需要时 不准时添加 clean 过滤器:
参见 commit 1a8630d (2016 年 1 月 29 日)作者:Lars Schneider (larsxschneider
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit a3764e7 ,2016 年 2 月 10 日)
convert
: treat an empty string for clean/smudge filters as "cat
"
git -c filter.myFilter.clean= add test.disable
^^
(empty value)
关于git - git可以在提交前过滤掉某些行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30945532/