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

2018-06-23 12:02:00 +08:00
 pheyer

想在家里和公司两台 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,应该就没有问题了

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

https://coding.net/u/cyio/p/dotfiles/git?public=true
zn
2018-06-23 13:08:51 +08:00
直接在 $HOME 创建一个仓库不就得了,然后加一个 .gitignore,内容是 * ,默认忽略所有文件,然后手动添加要管理的文件。
msg7086
2018-06-23 13:11:04 +08:00
@pheyer 人家都写了 git-dir=$HOME/.myconf/ 你还找 .git 么。
XGHeaven
2018-06-23 13:18:21 +08:00
像我这种几乎不会重装的人,没有备份的必要😂
Arnie97
2018-06-23 17:06:22 +08:00
有点意思,不过我用的也是 #4 的办法,比这个更简单
heikejia
2018-06-23 18:28:38 +08:00
把安装脚本写好就行了
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
2018-06-28 18:11:14 +08:00
@haoliang 软链接的话你要一定一个去设置,这个就不用了,省事多了吧
pheyer
2018-06-28 18:12:46 +08:00
@haoliang 你推荐的这个要额外装一个库,我觉得还是挺麻烦的,另外也不确定 Mac 上能不能装
m9rco
2019-01-16 15:26:29 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/465232

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX