你如何告诉git永久忽略文件中的变化? [英] How do you tell git to permanently ignore changes in a file?

查看:88
本文介绍了你如何告诉git永久忽略文件中的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个为网站存储数据的git存储库。它包含一个.htaccess文件,其中一些值适用于生产服务器。为了让我在网站上工作,我必须更改文件中的某些值,但我从不想提交这些更改,否则我会中断服务器。



由于.gitignore不适用于跟踪文件,因此我使用git update-index --assume-unchanged .htaccess来忽略文件中的更改,但这只在切换分支之前才起作用。



有没有办法让git忽略文件中的变化更改分支机构时请保持独立? (就像文件未被跟踪一样)。你可以使用 (a http://git-scm.com/docs/gitattributesrel =nofollow noreferrer> gitattribute过滤驱动,描述





每次更新工作目录时,您都有机会替换 .htaccess的内容与预定义的一个,为您的当前环境进行更正。

在清理阶段,您将恢复原始内容,就好像您从未触及该文件一样。


I'm working with a git repository that's storing data for a website. It contains a .htaccess file, with some values that are suitable for the production server. In order for me to work on the site, I have to change some values in the file, but I never want to commit these changes or I will break the server.

Since .gitignore doesn't work for tracked files, I was using "git update-index --assume-unchanged .htaccess" to ignore my changes in the file, however this only works until you switch branches. Once you change back to your original branch, your changes are lost.

Is there some way of telling git to ignore changes in a file and leave it alone when changing branches? (Just as if the file was untracked.)

解决方案

You could use a smudge/clean process (a gitattribute filter driver, described in ProGit)

Each time you update your working directory, you would have the opportunity to replace the content of your .htaccess with a predefined one, correct for your current environment.
In the clean stage, you would then restore the original content, as if you had never touched that file.

这篇关于你如何告诉git永久忽略文件中的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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