更好的方式让Git对我的变化视而不见 [英] Better way of making Git to turn a blind eye on my changes

查看:140
本文介绍了更好的方式让Git对我的变化视而不见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一些更清洁的方式让Git忽略我的一些变化,从不提交?
.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看到。

解决方案

看起来像这个过滤器的方法是最适合我的。

优点:


  1. 无需每次都使用自定义脚本或特殊命令。一次性安装。
  2. 没有额外的历史或隐藏提交。清理差异和修补程序。
  3. 提交错误信息的次数很少。
  4. 相对容易产生较小的偏差(例如在配置文件中覆盖一些端口号),就像简单的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:

  1. No need to use custom scripts or special commands every time. One-time setup.
  2. No extra commits in history or in stash. Clean diffs and patches.
  3. Low rick of committing the wrong thing.
  4. 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:

  1. Filter programs runs every time Git reads or writes the file, it can be slow (especially in Windows).

这篇关于更好的方式让Git对我的变化视而不见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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