git - 如何在 Git 中将我的 dotenv 文件和配置文件从一台计算机复制/备份到另一台计算机
问题描述
在 git 中存储秘密(.env 文件)通常不是一个好习惯。但是,当我需要移动计算机时,我通常必须将它们一个一个地复制和粘贴。
我不想复制整个 git 存储库,因为它还包含node_modules
并且将永远通过 Google。如何仅复制我的 env 文件?
解决方案
在您的站点目录中运行它
setopt sh_word_split # For zsh
dirs=$(find . -maxdepth 1 -type d -execdir test -d {}/.git \; -prune -print 2>/dev/null)
# store dotfiles here
[[ ! -d dotfiles ]] && mkdir dotfiles
dotfiles_path=$(cd dotfiles && pwd)
for dir in $dirs; do
originalPwd=$(pwd)
cd $dir
ignored=$(git status --ignored)
for file in $ignored; do
if [[ -f $file ]]; then
new_location="$dotfiles_path/$dir/$(dirname $file)"
mkdir -p $new_location
cp $file $new_location
fi
done
cd $originalPwd
done
将文件复制到 Google Drive:
cp -r dotfiles ~/Google\ Drive\
等待文件同步
在新计算机上,转到您的~/Sites
目录并执行
cp -r ~/Google\ Drive/dotfiles/* .
一切都使用最小的带宽同步:)
您也可以将其放入脚本和 cron 作业中以自动备份
env EDITOR=nano crontab -e
粘贴:
*/10 * * * * ~/Sites/backupEnv.sh
推荐阅读
- azure - 在 Azure 上托管 ClickOnce 的问题
- macros - notepad++ 如何将两个宏分配给同一个键?
- flutter - 更改特定行中 listView 中的图标
- kotlin - 如何启动接收器,获取“lateinit 属性 notificationManager 尚未初始化”
- php - 如何使用 PHP 强制下载 PDF 文件?
- python - 如何等待第二个下拉列表基于第一个在 Python 中使用 Selenium 加载
- python - BOW(Bag Of Words)和TextBlob之间的区别
- javascript - 如何访问chart.js自定义工具提示界面中的类变量
- python - 序列化 json 对象内的自定义对象
- java - 创建 Java 类以接收 JSON 对象