防止使用git意外签入密码文件

问题描述 投票:0回答:2

git 似乎没有做我想做的事,所以我需要一些建议。我有一个包含密码等敏感信息的配置文件。假设我已使用空白/通用值签入配置文件:

username =
password =

现在我用实际值填充它,然后将文件添加到.gitignore(文件名是build.properties)

username = bob
password = secretpassword

即使我已将其添加到 .gitignore,git 似乎仍然“看到它”。我应该在这里做什么?

hostname$ more .gitignore 
build
ant.build
*.swp
build.properties

hostname$ git status
# On branch dev
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   build.properties
#
no changes added to commit (use "git add" and/or "git commit -a")

我是不是误会了什么?

git
2个回答
21
投票

.gitignore
只会忽略尚未跟踪的文件。在您的情况下,您需要创建一个
password.file.template
并跟踪它(通过提交它),然后将真实的
password.file
放入
.gitignore
文件中。


4
投票

好吧,它说modified: build.properties,所以有人已经签入了这个文件。我的最佳猜测是:删除文件,提交更改,然后重新创建它而不签入。

© www.soinside.com 2019 - 2024. All rights reserved.