可以有条件地设置gitconfig选项吗? [英] Can gitconfig options be set conditionally?

查看:104
本文介绍了可以有条件地设置gitconfig选项吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Github我在几台不同的计算机和服务器上使用同一组点文件。在我直接控制的Mac和Linux机器上,我安装了Sublime Text 2并将其设置为我选择的git merge and commit编辑器。但是,在远程(即不在我的直接控制下)服务器上,我会选择使用vim。



我宁愿不为这些远程服务器创建并维护第二个 .gitconfig 。有没有办法做到这一点:

  [core] 
if [[$ IS_REMOTE -eq 1] ]。那么
editor =vim
else
editor =subl -n -w
fi

在哪里设置$ IS_REMOTE根据主机名?

解决方案

由于无法测试环境变量并以编程方式更改.gitconfig,并且由于脚本编写两个.gitconfig文件的创建感觉比我想提出的工作要多,我只需创建两个.gitconfig文件。在那些我可以设置Sublime Text 2作为编辑器的机器上,并且可以控制合并工具和diff工具,我将使用primarygitconfig作为我的符号链接的目标。在那些没有ST2作为选项的机器上,我将使用secondarygitconfig文件。

Via Github I use the same set of "dot files" on several different computers and servers. On the Macs and Linux boxes under my direct control I have Sublime Text 2 installed and set up as my git merge and commit editor of choice. However, on remote (i.e., not under my direct control) servers I would select to use vim.

I would rather not create and maintain a second .gitconfig for those remote servers. Is there a way to do something like this:

[core]
    if [[ $IS_REMOTE -eq 1 ]]; then
        editor = "vim"
    else
        editor = "subl -n -w"
    fi

where I've somehow set $IS_REMOTE based on the hostname?

解决方案

Since it isn't possible to test an environment variable and programmatically alter the .gitconfig, and since scripting the creation of two .gitconfig files feels like more work than I really want to put forth, I'm just going to create two .gitconfig files. On those machines where I can setup Sublime Text 2 as my editor, and have control over the merge tool and diff tool, I'll use the "primary" gitconfig as the target of my symbolic link. On those machines where I don't have ST2 as an option, I'll use the "secondary" gitconfig file.

这篇关于可以有条件地设置gitconfig选项吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆