让 Git 对我的更改视而不见的更好方法
有没有一些更简洁的方法让 Git 忽略我的一些更改并且从不提交它们? .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)
补丁 /tmp/pp 在每一行中添加了我的更改,其中包含“git_please_dont_look_here”。 Git 在将文件放入存储库之前删除所有此类行,并在签出文件时重新添加我的更改;我可以继续向 config_to_be_devied.xml
添加和提交有用的更改,但 Git 将看不到补丁中的更改。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看起来这种“过滤”方法最适合我。
优点:
缺点:
It looks like this "filter" approach is the best suited for me.
Pros:
Cons:
将它们放入单独的文件中,忽略 git 中的文件并将其连接到您的构建以便包含它?
Put them into separate file, ignore the file in git and hook it up to your build so it gets included?
尝试 git update-index --assume-unchanged --。对于源代码控制下的文件,它的作用类似于 gitignore。不过,该功能的最初目的是提高 git 检查包含大量文件的文件夹中的修改的性能。这是 doco:
try
git update-index --assume-unchanged --<path>
. It acts like gitignore for files under source control. The original purpose of the feature though, was to improve performance of git checking modifications in a folder with lots of files. Here is the doco:现在,默认配置已被跟踪,而您对默认配置的自定义则不会被跟踪。
Now the default config is tracked, and your customizations of the default config are not.
我对 git 不太熟悉。对于 Mercurial,我使用补丁队列 (MQ) 或搁置(类似于 git stash)来处理此类事情。
如果您的“可本地化”信息很容易找到(例如全部在一个配置文件中),那么 git stash 使用起来会很方便。
使用补丁队列稍微复杂一些,但一旦设置正确,效果会更好,因为您可以以透明的推送/弹出方式管理可本地化的信息。您可以在 git 此处 上找到补丁队列列表。
I am not all to familiar with git. With Mercurial I use a patch queue (MQ) or the shelve (similar to git stash) for such things.
git stash
can be convenient to use, if you're "localizable" information is easy to locate (e.g. all in a single config file).Using a patch queue is a little more complex but once setup correctly superior because you can manage localizable information in a transparent push/pop manner. You can find a list of patch queues on top of git here on SO.