防止现有文件在Git中获取更新 [英] Keep existing files from getting updates in Git

查看:49
本文介绍了防止现有文件在Git中获取更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个google_oauth_server.xml文件.它包含一个客户端ID,我希望不要将该客户端ID检入到存储库中.

I have a google_oauth_server.xml file in my project. It contains a client id, which I would like to not get checked into the repository.

<?xml version="1.0" encoding="utf-8"?>
<!-- Do not split into debug and release, as there is one server-->
<resources>
    <string name="google_server_client_id" templateMergeStrategy="preserve" translatable="false">
        ---my-code--
    </string>
</resources>

相反,我希望文件存在于存储库中,但用YOUR CODE HERE代替代码.

Instead, I want the file to exist in the repo, but with the words YOUR CODE HERE instead of the code.

我尝试用单词YOUR_CODE_HERE而不是代码来提交文件,然后将单词更改为实际的客户端ID,然后将文件添加到.gitignore中以防止提交,但是它不起作用,而git总是尝试使用客户端ID提交文件.

I tried committing a file with the words YOUR_CODE_HERE instead of the code, then changing the words to my actual client id, and then adding the file to .gitignore to prevent it from getting committed, but it does not work, and git always tries to commit the file with the client id.

推荐答案

git -update-index :

用户经常尝试使用假设不变和跳过工作树位来 告诉Git忽略对跟踪文件的更改.这不 由于Git仍可以根据其检查工作树文件,因此可以按预期工作 执行某些操作时的索引.通常,Git不会 提供一种忽略跟踪文件更改的方法,因此可以选择 建议解决方案.

Users often try to use the assume-unchanged and skip-worktree bits to tell Git to ignore changes to files that are tracked. This does not work as expected, since Git may still check working tree files against the index when performing certain operations. In general, Git does not provide a way to ignore changes to tracked files, so alternate solutions are recommended.

例如,如果要更改的文件是某种配置 文件,存储库可以包含一个示例配置文件,然后可以 复制到忽略的名称并进行修改.仓库甚至可以 包括将示例文件视为模板的脚本,然后进行修改和 自动复制.

For example, if the file you want to change is some sort of config file, the repository can include a sample config file that can then be copied into the ignored name and modified. The repository can even include a script to treat the sample file as a template, modifying and copying it automatically.

这篇关于防止现有文件在Git中获取更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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