在提交之前可以过滤掉某些行? [英] Can git filter out certain lines before commit?

查看:122
本文介绍了在提交之前可以过滤掉某些行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在github上有一个回购工作,我经常对我的 .py 文件发表评论,这些文件以# TODO:以保持个人注意事项。

 #TODO:做到这一点<代码> 

我显然不希望进行提交。



我希望GitHub在我即将提交它们时搜索所有文件,并且不包含以#TODO开头的行:



Git是否已经这样做?我知道某些版本控制像perforce已经有这个功能。



有什么想法?

解决方案

我希望GitHub在我要提交它们时搜索所有文件,而不要包含以#TODO开头的行:


GitHub(服务器端)不会那样做。



但是,您可以在本地仓库中注册 ,来自 Pro Git book



' clean 'filter 可以过滤出这些行(我不会讨论是否应该离开它们),并且该过滤器将自动应用于git commit。 >
这显然会移除所有 TODO ,其中包括其他人留下的内容,因此请小心处理:技术上 / em>可能,但是你必须确定它是否需要/有用。





2016年2月更新:使用git 2.8,即使你已经定义了一个git内容过滤器,你可以按时添加git without 在需要的情况下应用清洁过滤器:

请参阅 commit 1a8630d (2016年1月29日)作者: Lars Schneider( larsxschneider

(由合并Junio C Hamano - gitster - 提交a3764e7 ,2016年2月10日)


convert :将一个空白字符串作为/ code> cat




  git -c filter.myFilter.clean = add test.disable 
^^
(空值)


I have a repo on github that I am working out of and I often have comments on my .py files that starts with the "# TODO:" to keep a personal note of things to be done.

# TODO: do this <code>

I obviously do not want that to go in a commit.

I want GitHub to search all the files when I am about to commit them and not include lines that start with # TODO:

Does Git already do this? I know certain version control like perforce already have this feature.

Any thoughts?

解决方案

I want GitHub to search all the files when I am about to commit them and not include lines that start with # TODO:

GitHub (server side) won't do that.

But you can, in your local repo, register a content filter driver which will do that for you on git commit (like a sed '/^# TODO:/ d').

(image shown in "Customizing Git - Git Attributes", from "Pro Git book")

A 'clean' filter can filter out those lines (I won't discuss if you should leave them or not), and that filter will apply automatically on git commit.
That would obviously remove all TODO including ones left by others, so handle this with care: it is technically possible, but you have to determine if it is needed/useful in your case.


Update February 2016: with git 2.8, even if you had defined a git content filter, you can git add punctually without applying the clean filter if needed:

See commit 1a8630d (29 Jan 2016) by Lars Schneider (larsxschneider).
(Merged by Junio C Hamano -- gitster -- in commit a3764e7, 10 Feb 2016)

convert: treat an empty string for clean/smudge filters as "cat"

git -c filter.myFilter.clean= add test.disable
                            ^^
                          (empty value)

这篇关于在提交之前可以过滤掉某些行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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