部分分支或部分合并或其他方式来帮助我同步点文件? [英] Partial branch or partial merge or other way to help me to sync dotfiles?
问题描述
我不知道如何让我的要求缩短标题,如果没有意义,我感到抱歉。我会在这里解释:
许多人将他们的点文件放在bitbucket或github上,以便以后安装或配置,通过不同的PC进行同步。我做了同样的事情,但是我想做一些特别的事情,我不确定mecurial / git可以提供什么帮助。
我有:
我有3台机器,比如说Home,Office和Client,所有的Linux操作系统(可能是不同的发行版)。为了简化示例,假设我只想将一个文件 .zshrc
放入回购站中。问题是,这三个操作系统有不同的系统变量(或其他设置)。例如
- Office安装了JBOSS,然后在
.zshrc
中需要导出JBOSS_HOME var。 - 客户端安装了Oracle,然后导出不同的变量集。
- Office必须导出HTTP_PROXY,但HOME不是,客户端也需要它,但是代理值不同。
现在我所做的是,我将这些机器特定的设置(主要是导出,别名语句)提取到另一个文件,比如 myVar.sh
。并在 .zshrc
结尾处源代码。
因此,3台机器具有相同的部分(相同 .zshrc
)和不同部分( myVar.sh
)。
我想要什么: 在任何机器上,如果我找到了一些很好的设置,我更改
$ b
.zshrc
文件(公共部分)并按下。如果我更改了 myVar.sh $>,那么这些更改应该很容易与其他计算机同步(例如,通过拉动)
myVar.sh
。
我在做什么:
现在我拥有一个bitBucket上的Repo和三个分支(H,O,C)。在家用电脑上,我只是玩家支部。
问题是,如果我在一台电脑上更改了通用部件,则更改位于其自己的分支中,有点难以同步到另外两个。因为我永远不会合并这些分支。
我也考虑为不同的pc设置不同的目录。例如
/。zshrc
| - / HOME / myVar.sh
| - / Office /myVar.sh
| - / Client / myVar.sh
并编写shell脚本,例如检查$ HOST以决定将 myVar.sh
写入哪个目录。但我怀疑如果这是实现我的目标的最佳方式。当我看到我的dotfiles目录时,我看到所有3个设置。我应该小心,并输入正确的一个来读取文件。
在现实世界中,通用部分包含远远超过.zhsrc(tmux,vimrc,xdefault .. ),不同的部分也是如此。
我不知道是否可以以某种方式创建分支或在存储库上进行部分合并...
我使用hg远远超过git,如果hg可以解决它,我宁愿使用hg,如果不是,git也是可以接受的。除了克隆,推送,拉取,合并,ci以外,我没有太多的git体验。 现在,我应该怎么做
以及,感谢您阅读此...
编辑关于不同部分的更多信息
我会感谢大家给我的答案。正如我上面所说的,我的真机中的不同部分并不像 myVar.sh
那么简单。例如,我将公司笔记本电脑(Office)带到不同的客户端(大约有6个客户端,并非所有客户端都提供给我们PC,这很好,因为我可以在任何地方与Linux一起工作),并为每个客户配置打印机。我会把这些配置放在Repo中。因为如果有一天我不得不刷新我的系统,或硬盘失败,我可以很容易地设置这些打印机。其他的东西属于不同的部分,但我不能简单地源xxx就像
- 用于轨迹点的Xorg.conf
- .hgrc文件(因为在公司中我们有自己的repo,uid,pwd,proxy ..)
-
一些预配置的systemd模块,基本上是.conf文件。但是机器特定的,例如radeon.conf仅适用于我的家用笔记本电脑。而客户端电脑根本没有安装systemd。
$ b p>正如我现在说的,我用3种分支方式,并有一个
myConf
目录,在这个目录中我有 getConf.sh
,将dotfiles,不同的confs等复制到 myConf
中。实际上, getConf.sh
也属于不同的部分,因为脚本对于所有的pcs不同。 因此,我认为在这种情况下, if-else / switch
然后 source
可能不起作用。
昨天我只带了.zshrc文件,并尝试使示例变得简单。如果它误导了你们,对此很抱歉。
我的首选方法是为每个文件在同一个目录中设置一个特定于主机的版本 - 类似到同一个文件多个目录,然后通过变量插值将它包含在我的主文件中。所以〜/ .bashrc
里面有这个this:
if [ -f〜/ .bashrc- $ HOSTNAME];然后
源〜/ .bashrc- $ HOSTNAME
fi
假设这是偶数在zsh中更漂亮,但想法是如果特定于主机的文件在最后存在,那么适用于所有机器的所有内容都会出现在主〜/ .bashrc本身中。
I don't know how to make my requirement short in title, sorry if it is not meaningful. I will explain here:
Many people put their dotfiles on bitbucket or github, to ease later installation or configuration, sync over different pc. I did the same, however I want to do something special, I am not sure how mecurial/git could help.
What I have:
I have 3 machines, say Home, Office and Client, all linux OS (could be different distributions). To make the example simple, say I just want to put one file the .zshrc
into repo. The problem is, the three OS have different system variables(or other settings). e.g.
- Office has JBOSS installed, then in
.zshrc
I need export JBOSS_HOME var. - Client has Oracle installed, then export different set of vars.
- Office has to export HTTP_PROXY, but HOME not, Client needs it too, but different proxy value etc.
Now what I did is, I extract those machine specific settings (mostly export, alias statement) to another file, say myVar.sh
. and source it at the end of the .zshrc
.
So 3 machines have common part (same .zshrc
), and different parts (myVar.sh
).
What I want:
on any machine, if I found some nice settings, I change the
.zshrc
file (common part) and push. The changes should be easily sync to other machines (by pull, for example)if I changed the
myVar.sh
(different part) on HOME, and push, it should not affect Office'smyVar.sh
if I do pull on Office machine.
What I am doing:
now I have one Repo on bitBucket, and three branches (H,O,C). On Home PC, I just play with Home branch. Same for Office, Client.
The problem is, if I changed the common part on one pc, the change is in its own branch, a little bit difficult to sync to the other two. Because I would never merge those branches.
I also think about to mk different directories for different pc. e.g.
/.zshrc
|--/HOME/myVar.sh
|--/Office/myVar.sh
|--/Client/myVar.sh
and write shell script, e.g. check $HOST to decide writing myVar.sh
to which directory. but I doubt that if it is the best way to achieve my goal. And when I look my dotfiles dir, I see all 3 pcs' setting. I should be careful and enter the correct one to read the file.
In real world, the common part contains much more than .zhsrc (tmux,vimrc,xdefault..), so does the different part.
I don't know can we somehow make a partial branch or do a partial merge on a repository...
I use hg much more than git, if hg can solve it I would prefer hg, if not, git is also acceptable. I don't have much git experience except for clone, push, pull, up, merge,ci.
now, how should I do?
and, thank you for reading this...
EDIT more about the different part
I would thank you all guys for giving me answers. As I said above, the different part in my real machines is not as simple as myVar.sh
. For example, I take my company-laptop (Office) to different clients (There are about 6 clients, not all clients provide us PCs, it is good because I could work with Linux everywhere), and configured printers for each by cups. I would put those configurations in Repo too. Because if one day I have to refresh my system, or harddisk failed, I could setup those printers very easy. Other things that belongs to different part but I cannot simply "source xxx" like
- Xorg.conf for trackpoint
- .hgrc file (since in company we have our own repo, uid, pwd, proxy..)
some pre-configured systemd modules, basically .conf files. But machine specific, e.g. radeon.conf only for my Home laptop. And Client pc has no systemd installed at all.
That's why I thought about different directory for PCs.
As I said right now I am with 3 branches way, and have a myConf
directory, within this directory I have getConf.sh
, to copy dotfiles, different confs etc to myConf
. In fact the getConf.sh
belongs to different part too, because the script is not same for all pcs.
Therefore I think the if-else/switch
then source
may not work in this case.
Yesterday I just took the .zshrc, and try to make the example simple. If it mislead you guys, sorry about that.
My preferred way to do this is to have a host-specific version for each file all in the same directory -- similar to your same file multiple directories, and then include it via variable interpolation in my main file. So ~/.bashrc
has inside of this this:
if [ -f ~/.bashrc-$HOSTNAME ] ; then
source ~/.bashrc-$HOSTNAME
fi
Presumably that's even prettier in zsh, but the idea is if a host-specific file exists source it at the end, and of course anything that applies on all machines goes in the main ~/.bashrc itself.
这篇关于部分分支或部分合并或其他方式来帮助我同步点文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!