更好的方式让Git对我的变化视而不见 [英] Better way of making Git to turn a blind eye on my changes
问题描述
.gitattributes:
config_to_be_deviated.xml filter = qqq
.git / config:
[filterqqq]
clean =perl -ne 'print print / git_please_dont_look_here /'
smudge =(Q = $(mktemp)&& cat> $ Q && patch -s $ Q< / tmp / pp && cat $ Q && rm $ Q)
patch / tmp / pp将每行中的git_please_dont_look_here添加到我的更改中。
在将文件存入存储库之前,Git将删除所有这些行,并在检出时读取我的更改;我可以继续添加并提交有用的更改到 config_to_be_deviated.xml
,但修补程序中的更改不会被Git看到。
看起来像这个过滤器的方法是最适合我的。
优点:
- 无需每次都使用自定义脚本或特殊命令。一次性安装。
- 没有额外的历史或隐藏提交。清理差异和修补程序。
- 提交错误信息的次数很少。
- 相对容易产生较小的偏差(例如在配置文件中覆盖一些端口号),就像简单的sed脚本,用于涂抹和清洁。
缺点:$ b
$ b
在每次Git读取或写入文件时都会运行过滤程序,它可能很慢(特别是在Windows中)。
Is there some cleaner way to make Git just ignore some of my changes and never commit them? .gitattributes:
config_to_be_deviated.xml filter=qqq
.git/config:
[filter "qqq"] clean = "perl -ne 'print unless /git_please_dont_look_here/'" smudge = (Q=$(mktemp) && cat > $Q && patch -s $Q < /tmp/pp && cat $Q && rm $Q)
The patch /tmp/pp adds my changes with "git_please_dont_look_here" in each line.
Git removes all such lines before getting the file into repository and readds my changes when checking out it; I can continue adding and committing useful changes to config_to_be_deviated.xml
, but changes in the patch will not be seen by Git.
It looks like this "filter" approach is the best suited for me.
Pros:
- No need to use custom scripts or special commands every time. One-time setup.
- No extra commits in history or in stash. Clean diffs and patches.
- Low rick of committing the wrong thing.
- Relatively easy to make minor deviations (like overriding some port number in config file), like simple sed script both for smudge and for clean.
Cons:
- Filter programs runs every time Git reads or writes the file, it can be slow (especially in Windows).
这篇关于更好的方式让Git对我的变化视而不见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!