“ git update-index --assume-unchanged”;默认情况下 [英] "git update-index --assume-unchanged" by default

查看:241
本文介绍了“ git update-index --assume-unchanged”;默认情况下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,在给定的一组文件中,git中是否有一种方法可以使 git update-index-假定未更改的FILE_NAME 的结果?例如,一个git config文件列出了默认情况下不会跟踪其更改的文件,这样在克隆存储库后就不必运行命令了吗?这些文件将以默认格式存在于存储库中,并由开发人员提取,并且对文件所做的任何更改都不会被跟踪或跟踪提取。



例如:我有一个web.config文件,该文件带有占位符,用于项目所使用的连接字符串。理想情况下,开发人员将克隆存储库,并用指向其本地资源的连接字符串替换这些占位符。无需运行任何命令。这样,这些更改将保留在后拉中,除非在仓库中更改了web.config文件的格式,并且它们的本地更改不会被推送到仓库中。



在git中使用配置文件可以实现吗?还是我必须始终为假定不变的文件集运行命令?

解决方案

一种更好的方法(比尝试使用假定不变 skip-worktree 来扭曲索引是 not 完全跟踪这些文件,但要生成它们(并确保它们位于.gitignore中,即被跟踪并忽略了它们)。



那样,您可以随意在本地修改它们,而不必完全管理它们的Git索引状态(因为它们没有被跟踪)



为此,您需要跟踪:




  • a file.tpl (带有占位符值的模板文件)。

  • 一个能够获取模板文件并生成实际文件的脚本(仍然是未跟踪的私有文件)

  • a .gitignore 忽略生成的文件

  • a .gitattribute 声明污迹内容过滤器(如下所示)



通过 a href = https://stackoverflow.com/a/10571580/6309>内容过滤器驱动程序 ,使用

(图片来自自定义Git-Git属性 来自 Pro Git书))



一旦在本地配置中声明了内容文件驱动程序,它将在 git checkout 上自动生成您的(未跟踪)文件。

请参见 最佳实践-Git +构建自动化-保持配置独立


Is there a way in git to have the result of git update-index --assume-unchanged FILE_NAME by default on a given set of files? For example, a git config file that lists files whose changes are not tracked by default, so that we don't have to run the command after we clone the repo? The files would exist in the repository in a default format, be pulled by the developers, and whatever changes they make to the file wouldn't be tracked nor overwritten by posterior pulls.

For example: I have a web.config file with a placeholder for connection strings that are used by the project. Ideally, the developer would clone the repo and replace those placeholders with connection strings pointing to their local resources. No need to run any commands. That way, these changes would be preserved in posterior pulls, unless the format of the web.config file changed in the repo, and their local changes wouldn't be pushed to the repo.

Is this achievable in git with a config file? Or do I always have to run the command for the "set of files to assume unchanged"?

解决方案

A better approach (than trying to twek the index, with assume-unchanged or skip-worktree) is to not track those files at all, but to generate them (and make sure they are in the .gitignore, that is not tracked and ignored)

That way, you can modify them locally at will, without having to manage their Git index state at all (since they are not tracked)

For that, you version and track:

  • a file.tpl (template file with placeholder values).
  • a script able to take a template file, and produce the actual file (which remains untracked, private)
  • a .gitignore which ignores the resulting generated file
  • a .gitattribute declaring a smudge content filter (see below)

The generation of the file is automated through a content filter driver, using a .gitattributes declaration.


(image from "Customizing Git - Git Attributes" from "Pro Git book"))

Once you declare that content filer driver in your local config, it will automatically, on git checkout, generate your (not tracked) file for you.
See a complete example in "Best practice - Git + Build automation - Keeping configs separate".

这篇关于“ git update-index --assume-unchanged”;默认情况下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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