代码之家  ›  专栏  ›  技术社区  ›  Malvineous

如何让git永久忽略文件中的更改?

git
  •  18
  • Malvineous  · 技术社区  · 16 年前

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

    由于.gitinore对跟踪的文件不起作用,所以我使用了“git update index--assume unchanged.htaccess”来忽略我在文件中所做的更改,但是这只在切换分支之前起作用。一旦更改回原来的分支,所做的更改就会丢失。

    有没有办法告诉git忽略文件中的更改 和 换树枝时别管它(就像文件没有被追踪一样。)

    3 回复  |  直到 16 年前
        1
  •  10
  •   Community Mohan Dere    9 年前

    你需要一个 smudge/clean process gitattribute filter driver ,描述 in ProGit

    clean smudge

    每次更新工作目录时,都有机会替换工作目录的内容 .htaccess 使用一个预定义的,适合您当前的环境。

        2
  •  10
  •   François Beausoleil    13 年前

    只需告诉git假定文件没有更改:

    $ git update-index --assume-unchanged FILE [FILE ...]
    

       --assume-unchanged, --no-assume-unchanged
           When these flags are specified, the object names recorded for the paths are not updated. Instead, these options set and unset the "assume unchanged" bit for the paths. When the "assume unchanged" bit is on, git stops checking the
           working tree files for possible modifications, so you need to manually unset the bit to tell git when you change the working tree file. This is sometimes helpful when working with a big project on a filesystem that has very slow
           lstat(2) system call (e.g. cifs).
    
           This option can be also used as a coarse file-level mechanism to ignore uncommitted changes in tracked files (akin to what .gitignore does for untracked files). Git will fail (gracefully) in case it needs to modify this file in the
           index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.
    

    发现于 How to Ignore Changes in Tracked Files With Git

        3
  •  2
  •   Michael Reinsch    16 年前

    基于部署的方法:使用工具(如capistrano/cfengine/…)自动化部署过程。这有很多优点,其中之一就是能够将配置与代码分开。