Git bash 主目录与 Git 扩展名和 Git Bash 不同

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8560064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:33:11  来源:igfitidea点击:

Git bash home directory different from Git extension than Git Bash

gitgit-extensions

提问by Steve B

If i run Git bash from Git Extention (CTRL+G), my home directory is %USERPROFILE%, which is ok.

如果我从 Git Extention ( CTRL+ G)运行 Git bash ,我的主目录是 %USERPROFILE%,这没问题。

If I run Git bash from the context menu of a git repo folder, or if I run Git bash from the start menu, my home directory is %HOME%, which is different.

如果我从 git repo 文件夹的上下文菜单运行 Git bash,或者如果我从开始菜单运行 Git bash,我的主目录是 %HOME%,这是不同的。

How can I set up git bash to always use %USERPROFILE% as home directory (I have the .ssh folder within) ?

如何设置 git bash 以始终使用 %USERPROFILE% 作为主目录(我有 .ssh 文件夹)?

If it can help, on git bash run from Git Ext, I have :

如果有帮助,在从 Git Ext 运行的 git bash 上,我有:

$ echo $HOME
/c/Users/mylogin

Same command on git bash run directly :

git bash 上的相同命令直接运行:

$ echo $HOME
/h

h:is my corporate home directory

h:是我的公司主目录

What can I do ?

我能做什么 ?

回答by VonC

The git bash provided with msysgitin its repois a script you can edit, in order to set HOMEto %USERPROFILE%.
It is basically what it does by default, except if HOMEis already defined, the git bash script won't modify that value (but you can, if you edit said script).

msysgit其 repo 中提供的 git bash是一个您可以编辑的脚本,以便设置HOME%USERPROFILE%.
它基本上是默认情况下所做的,除非HOME已经定义,否则git bash 脚本不会修改该值(但您可以,如果您编辑所述脚本)。

I suspect that, in your corporate environment, HOMEis defined to a network drive, in order for various configuration files (maven, ssh, ...) to be stored on a remote, secure and backed-up drive.
That would explain why HOMEis notchanged by the Git bash script.
The Git Extension obviously isn't as careful as the first script, and will change/define whatever value it needs.

我怀疑,在您的公司环境中,它HOME被定义为网络驱动器,以便将各种配置文件(maven、ssh 等)存储在远程、安全和备份的驱动器上。
这可以解释为什么HOME被Git的bash脚本改变。
Git 扩展显然不像第一个脚本那么小心,并且会改变/定义它需要的任何值。



As the OP Steve Bcomments:

正如OP Steve B评论的那样:

The HOMEis set, for the Git bash, in etc/profile:

HOME被设定为Git的庆典,在etc/profile

# Set up USER's home directory
if [ -z "$HOME" -o ! -d "$HOME" ]; then
  HOME="$HOMEDRIVE$HOMEPATH"
  if [ -z "$HOME" -o ! -d "$HOME" ]; then
    HOME="$USERPROFILE"
  fi
fi

I removed the first candidate home location, and it works.

我删除了第一个候选家庭位置,它有效。