隐藏GitHub的令牌的.gitconfig [英] Hiding GitHub token in .gitconfig

查看:1139
本文介绍了隐藏GitHub的令牌的.gitconfig的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想存储所有我在GitHub上点文件,其中的.gitconfig这需要我来隐藏的.gitconfig GitHub的令牌。

I would like to store all of my dotfiles on GitHub, including .gitconfig which requires me to hide the GitHub token in the .gitconfig.

要做到这一点我有的.gitconfig隐藏令牌文件,该文件是我打算编辑和混帐下隐藏标记放文件:

To do so I have a ".gitconfig-hidden-token" file which is the file I intend to edit and put under git that hides the token:

...
[github]
user = giuliop
token = --hidden--
...

和一个shell脚本,我需要,如果我修改的.gitconfig隐藏令牌文件创建的.gitconfig文件启动:

And a shell script which I need to launch if I modify the ".gitconfig-hidden-token" file to create the ".gitconfig" file:

cp .gitconfig .gitconfig.backup
sed 's/--hidden--/123456789/' .gitconfig-hidden-token > .gitconfig

其缺点是需要手动启动脚本,每次我modidy文件。有没有更好的,完全自动化的方式来做到这一点?

The drawback is the need to manually launch the script everytime I modidy the file. Is there a better, fully automated way to do this?

推荐答案

添加您的.gitconfig与 git的添加-N

Add your .gitconfig with git add -N.

然后 git的添加-p 它,编辑大块,与任何更换令牌,推动这一点。无需额外的文件这样的。

Then git add -p it, edit the hunk, replace the token with anything, and push that. No need for an extra file this way.

附录:关于你的文件的补充修改,使用 git的添加-p 再次,和编辑大块,使您最初的操作不会被覆盖。

Addendum: on additional modifications of your file, use git add -p again, and edit the hunk so that your initial manipulation not be overwritten.

这篇关于隐藏GitHub的令牌的.gitconfig的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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