在Git中忽略对文件的更改而不将其从Repo中移除? [英] Ignore changes to a file in Git without removing it from the Repo?

查看:154
本文介绍了在Git中忽略对文件的更改而不将其从Repo中移除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是这种情况:我们有几个配置文件,当用户克隆回购站时,他们会修改这些配置文件。这些文件本身的结构使其变得快速,简单和容易 - 但这意味着任何执行git add *或git commit -a的用户最终都会将其发送回服务器,并进行更改!



这不仅会在下一次他下手的时候破坏下一个人的东西(他需要每次合并并处理他不应该需要的文件冲突),这意味着用户可能很容易意外地打破了我们正在进行的持续集成测试。



我想要的是git ignore的效果(它不小心如果它被改变了,它不会提交它),但不必完全删除文件。如果我们也可以以某种方式强制对文件进行更改,那就太好了。



我知道在SVN中有这样做的方法,我认为Git必须具有相同的功能。

解决方案

  git update-index --assume-unchanged< filename> 

(它旨在实际用于不同的目的 - 改善git操作的性能,使其不是最优化的文件系统,你可以指示git假定某些文件没有被触及,你可以用它来暂时忽略被跟踪的文件)

你也可以用其他方法其中人们处理配置文件,比如有一个模板配置文件,用户创建他们特定的配置文件(后者被忽略)等。


This is the situation: We have several configuration files, and when a user clones the repo it is expected they will modify these configuration files. The files themselves are structured to make this quick, simple, and easy - but it means that any user doing a "git add *" or "git commit -a" ends up sending them back to the server with the changes already made!

Not only does this break things for the next person next time he pulls (he'll need to merge every time and handle the conflicts for a file he shouldn't even need), it means a user can very easily accidentally break the continuous integration testing we've got going.

What I want is the effect of git ignore (it doesn't care if it gets changed, it won't commit it), but without having to remove the file completely. It would be nice if we could also force a change to the file somehow.

I know there are ways to do this in SVN, I figure Git must have an equivalent.

解决方案

git update-index --assume-unchanged <filename>

( it is intended for a different purpose actually - to improve the performance of git operations on not so optimal file system whereby you can instruct git to assume that certain files are not touched. You can use it to "temporarily" ignore tracked files)

You can also look at alternate ways in which people handle configuration files, like having a template config file that the users create their specific config file out of ( the latter being ignored) etc.

这篇关于在Git中忽略对文件的更改而不将其从Repo中移除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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