如何阻止Git跟踪此提交文件中的任何更改? [英] How do I stop Git from tracking any changes to a file from this commit forward?

查看:92
本文介绍了如何阻止Git跟踪此提交文件中的任何更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库配置文件,其默认值不重要。但是,对此文件的任何更改都将包含敏感信息,这些信息不应在回购中进行跟踪。



我希望将来可以使用Git存储库来包含默认版本,但忽略任何用户所做的更改。



以下内容保留本地配置,但会将删除推送到回购站,导致未来的回收问题。

  catapp / dir / config.file>> .gitignore 
git rm --cached app / dir / config.file

这个工作,但并没有坚持过去的推动回购。

  git update-index --assume-unchanged app / dir / config.file 

这似乎是围绕敏感信息进行版本控制的常见要求,但我无法找到解决方案。

解决方案

像往常一样,github在这方面有一个很棒的文档。



https://help.github.com/articles/ignoring-files#ignoring -versioned-files



以下是相关代码片段:


忽略版本化文件



版本库中的某些文件经常更改,但很少提交。通常,这些是各种编辑的本地配置文件,但绝不应向上游提交。 Git让你可以忽略这些文件,假设它们没有变化。


  1. 在Terminal中,导航到你的Git仓库的位置。

  2. 在终端中运行以下命令:

git update-index - 假设 - 不变的路径/ to / file.txt



一旦你像这样标记一个文件,Git完全忽略它的任何改变。它在运行 git status git diff 时不会显示,也不会被提交。



要让Git重新跟踪文件,只需运行:

git update-index --no -assume-unchanged path / to / file.txt



I have a database configuration file that has default values that are unimportant. However, any changes to this file would contain sensitive information that should not be tracked in the repo.

I would like future pulls of the Git repository to include the default version but disregard any changes made by any user.

The following keeps a local configuration but pushes the delete to the repo resulting in issues for future pulls.

cat "app/dir/config.file" >> .gitignore
git rm --cached app/dir/config.file

The following does the job but does not persist past the push to the repo.

git update-index --assume-unchanged app/dir/config.file

This seems like a common requirement for version control around sensitive information but I can't seem to find a solution.

解决方案

As usual github has a great doc on this.

https://help.github.com/articles/ignoring-files#ignoring-versioned-files

Here's the relevant snippet:

Ignoring versioned files

Some files in a repository change often but are rarely committed. Usually, these are various local configuration files that are edited, but should never be committed upstream. Git lets you ignore those files by assuming they are unchanged.

  1. In Terminal, navigate to the location of your Git repository.
  2. Run the following command in your terminal:

git update-index --assume-unchanged path/to/file.txt

Once you mark a file like this, Git completely ignores any changes on it. It will never show up when running git status or git diff, nor will it ever be committed.

To make Git track the file again, simply run:

git update-index --no-assume-unchanged path/to/file.txt.

这篇关于如何阻止Git跟踪此提交文件中的任何更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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