V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
pheyer
V2EX  ›  程序员

看到一个比较优雅的用 git 管理 dotfiles 的办法

  •  
  •   pheyer · 2018-06-23 12:02:00 +08:00 · 5210 次点击
    这是一个创建于 2105 天前的主题,其中的信息可能已经有所发展或是发生改变。

    想在家里和公司两台 Mac 之间同步配置文件,搜到了这个解决方案:

    The best way to store your dotfiles: A bare Git repository - Atlassian Developers

    I use: git init --bare $HOME/.myconf alias config='/usr/bin/git --git-d... | Hacker News

    别人写的中文介绍:使用 git 管理 dotfiles

    主要用到的命令:

        git init --bare $HOME/.myconf
        alias config='/usr/bin/git --git-dir=$HOME/.myconf/ --work-tree=$HOME'
        config config status.showUntrackedFiles no
    #where my ~/.myconf directory is a git bare repository. Then any file within the home folder can be versioned with normal commands like:
        config status
        config add .vimrc
        config commit -m "Add vimrc"
        config add .config/redshift.conf
        config commit -m "Add redshift config"
        config push
    

    方式略有点奇葩,不过好处是不用搞什么软链接。里面有一些 git 黑魔法,大家也可以学学

    在我的理解里,git init --bare 一般是用于创建远程仓库的,它这里一开始创建的就是远程仓库

    如果我也想把这个库同时 push 到 github 上去该怎么做?我想的是需要在电脑本地另外的位置 git clone 这个库,然后增加一个 github remote,应该就没有问题了

    12 条回复    2019-01-16 15:26:29 +08:00
    congeec
        1
    congeec  
       2018-06-23 12:39:18 +08:00 via iPhone
    Dropbox 实时同步。反正也没多少东西不占空间
    pheyer
        2
    pheyer  
    OP
       2018-06-23 13:00:06 +08:00
    奇怪的是能 config push,不能 config pull,用 config remote -v 发现没有远程分支,还有.git 文件在哪里,可能是因为没有 git clone 这个过程?
    在另外位置的 dotfile 文件里添加了一个新文件,push 到$HOME.myconf 库,不知道怎么让它显示出来
    cyio
        3
    cyio  
       2018-06-23 13:08:12 +08:00
    我用的是这个方案,快一年了

    https://coding.net/u/cyio/p/dotfiles/git?public=true
    zn
        4
    zn  
       2018-06-23 13:08:51 +08:00 via iPhone
    直接在 $HOME 创建一个仓库不就得了,然后加一个 .gitignore,内容是 * ,默认忽略所有文件,然后手动添加要管理的文件。
    msg7086
        5
    msg7086  
       2018-06-23 13:11:04 +08:00
    @pheyer 人家都写了 git-dir=$HOME/.myconf/ 你还找 .git 么。
    XGHeaven
        6
    XGHeaven  
       2018-06-23 13:18:21 +08:00 via Android
    像我这种几乎不会重装的人,没有备份的必要😂
    Arnie97
        7
    Arnie97  
       2018-06-23 17:06:22 +08:00
    有点意思,不过我用的也是 #4 的办法,比这个更简单
    heikejia
        8
    heikejia  
       2018-06-23 18:28:38 +08:00 via iPhone
    把安装脚本写好就行了
    haoliang
        9
    haoliang  
       2018-06-25 00:25:48 +08:00
    > 不过好处是不用搞什么软链接。

    难道用软链接有什么坏处?

    > 方式略有点奇葩,... 里面有一些 git 黑魔法

    这怎么跟优雅有点远了吧? 看看这个[stow]( http://brandon.invergo.net/news/2012-05-26-using-gnu-stow-to-manage-your-dotfiles.html)
    pheyer
        10
    pheyer  
    OP
       2018-06-28 18:11:14 +08:00
    @haoliang 软链接的话你要一定一个去设置,这个就不用了,省事多了吧
    pheyer
        11
    pheyer  
    OP
       2018-06-28 18:12:46 +08:00
    @haoliang 你推荐的这个要额外装一个库,我觉得还是挺麻烦的,另外也不确定 Mac 上能不能装
    m9rco
        12
    m9rco  
       2019-01-16 15:26:29 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3976 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 10:21 · PVG 18:21 · LAX 03:21 · JFK 06:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.