我正在使用一个存储网站数据的git存储库.它包含一个.htaccess文件,其中包含一些适用于生产服务器的值.为了让我在网站上工作,我必须更改文件中的一些值,但我从不想提交这些更改,否则我将破坏服务器.
由于.gitignore不适用于跟踪文件,我使用"git update-index --assume-unchanged .htaccess"来忽略我在文件中的更改,但是这只能在切换分支之前有效.一旦您更改回原始分支,您的更改就会丢失.
有没有办法告诉git忽略文件中的更改并在更改分支时不管它?(就像文件未被跟踪一样.)
Fra*_*eil 11
只需告诉git假设文件未更改:
$ git update-index --assume-unchanged FILE [FILE ...]
Run Code Online (Sandbox Code Playgroud)
从手册:
--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.
Run Code Online (Sandbox Code Playgroud)
您可以使用涂抹/清理过程(一个gitattribute过滤器驱动程序,在ProGit中描述)

每次更新工作目录时,您都有机会.htaccess用预定义的内容替换您的内容,以更正您当前的环境.
在干净的阶段,您将恢复原始内容,就像您从未接触过该文件一样.
| 归档时间: |
|
| 查看次数: |
7229 次 |
| 最近记录: |