繁体   English   中英

如何在 Git 中将我的 dotenv 文件和配置文件从一台计算机复制/备份到另一台计算机

[英]How do I copy/backup my dotenv files and config files from one computer to another in Git

在 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\

等待文件同步

在新计算机上,go 到您的~/Sites目录并执行

cp -r ~/Google\ Drive/dotfiles/* .

一切都使用最小的带宽同步:)

您也可以将其放入脚本和 cron 作业中以自动备份

env EDITOR=nano crontab -e

粘贴:

*/10 * * * * ~/Sites/backupEnv.sh

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM