与 GNU Stow 的“--adopt”选项相反?

JBe*_*ley 8 dot-files stow

我按照本指南使用GNU Stow来管理我的点文件。这对于机器上没有预先存在的点文件的情况非常有效。例如,如果没有文件,则以下内容可以正常工作:~/.config/foo.cfg

~/.dotfiles$ mkdir -p foo/.config
~/.dotfiles$ echo My config > foo/.config/foo.cfg
~/.dotfiles$ stow foo
~/.dotfiles$ ls -l ~/.config
lrwxrwxrwx 1 user group 21 Dec  6 19:03 ~/.config -> .dotfiles/foo/.config
Run Code Online (Sandbox Code Playgroud)

~/.config/foo.cfg如果已经存在,它就变得不那么简单:

~/.dotfiles$ stow foo
WARNING! stowing bar would cause conflicts:
  * existing target is neither a link nor a directory: foo.cfg
All operations aborted.
Run Code Online (Sandbox Code Playgroud)

到目前为止,我能找到的唯一解决方案是手动删除~/.config/foo.cfg并重新运行stow foo. 当向可能有数十个预先存在的 .dot 文件的新计算机配置 stow 存储库时,这是相当尴尬的,并且基本上违背了使用 stow 管理点文件的目的。

斯托有--adopt选择权。运行的stow --adopt foo效果是用计算机上foo预先存在的文件替换存储的文件,然后创建符号链接。foo我正在寻找的是达到相反效果的方法;将计算机的 .dotfiles 替换为存储版本的符号链接,以便可以使用 Git 存储库中的存储点文件来配置新计算机。

这似乎是使用 Stow 管理点文件的一个明显要求,我觉得我错过了一些东西和/或问题已经解决了。

有任何想法吗?

小智 6

我遇到了同样的限制,并且我发现了一个与该--adopt选项配合良好的工作流程。正如Stow 文档中所述

\n
\n

...它允许目标树中的文件(其内容可能与 stow package\xe2\x80\x99s 安装映像中的等效版本不同)被采用到包中,然后通过运行类似 \xe2\x80\ 的内容进行比较x98git diff ...\xe2\x80\x99 在 stow 包内,最后要么保留(例如通过 \xe2\x80\x98git commit ...\xe2\x80\x99)或丢弃(\xe2\x80\x98git checkout头...\xe2\x80\x99)。

\n
\n

我的工作流程:

\n
    \n
  1. stow使用该选项运行--adopt
  2. \n
  3. 使用 . 将“采用的”文件与我的存储库中最初的文件进行比较git diff
  4. \n
  5. 使用 放弃“已采用”文件引入的所有更改git reset --hard,将整个目录恢复到上次提交的状态。
  6. \n
\n

例子:

\n
# Running from inside .dotfiles repository\n\xe2\x9d\xaf tree . -a\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 bash\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 .bashrc\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 .xprofile\n\n# Stow bash folder as usual and note conflicts (.bashrc in this case)\n\xe2\x9d\xaf stow bash\nWARNING! stowing bash would cause conflicts:\n  * existing target is neither a link nor a directory: .bashrc\nAll operations aborted.\ne conflicts\n\n# Rerun Stow with --adopt flag to place conflicting files in .dotfiles repo (no warnings)\n\xe2\x9d\xaf stow bash --adopt\n\n# Use git diff to compare adopted and committed file\n\xe2\x9d\xaf git diff\ndiff --git a/bash/.bashrc b/bash/.bashrc\nindex cbd6843..0ac2879 100644\n--- a/bash/.bashrc\n+++ b/bash/.bashrc\n@@ -1,121 +1 @@\n... Line changes are listed ...\n\n# Discard adopted file and revert back to contents as per last commit\n\xe2\x9d\xaf git reset --hard\n\n# Done\n
Run Code Online (Sandbox Code Playgroud)\n

我是 dotfiles 和 Stow 的新手,因此可能缺少一些限制。到目前为止我对结果很满意。

\n