问题描述
在我们的git
存储库中,例如,settings.ini
包含一堆配置数据.当我在本地测试我们的程序时,该程序会自动更改文件中的某些值,例如本地目录路径或IP地址等,这些值对于上游的任何人都不感兴趣,但是设置模块的所有者当然可以添加新的设置,我需要下载.
In our git
repository there is, say, settings.ini
that contains a bunch of configuration data. When I test our program locally, the program automatically changes some values in the file such as local directory paths or IP address, etc, which are of no interest to anyone upstream, but of course the owner of the settings module might add new settings that I need to download.
当前,我们使用 Gitflow模式,我正在使用某个功能,但是随后当我尝试执行git flow feature finish my_feature
时,我得到一个错误:
Currently, we use the Gitflow pattern, so I work on a feature, but then when I try to do git flow feature finish my_feature
I get an error:
当然,git checkout -- settings.ini
或git stash
可以解决这个问题,但是有没有办法将文件标记为忽略本地更改",这样我就可以停止获取错误并保留我的更改?
Of course, git checkout -- settings.ini
or git stash
gets me around this, but is there a way to mark a file as "ignore local changes" so I can stop getting the error and keep my changes?
推荐答案
在此处查看此博客文章:
Have a look at this blog post here:
https://www.jimbobbennett.io/hiding-api- keys-from-git/
这是一种用于从git中隐藏"信息的技术,该技术基本上是根据需要将文件添加到存储库中来添加文件,然后运行命令:
This has a technique for "hiding" information from git, which basically entails adding the file as you would want it to be checked into the repository, then run the command:
git update-index --assume-unchanged ./<your file name here>
这将告诉git忽略以后对该文件的任何更改.
This will tell git to ignore any future changes to the file.
很显然,如本文所述,如果您确实想对文件进行更改,则需要再次更新文件.
Obviously, as noted in the article, if you do want to actually make changes to the file you will need to update the file again.
这篇关于本地忽略文件修改,而不是远程忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!