在Windows安装的GIT bash中更改〜目录的位置 [英] Change the location of ~ directory in a Windows install of GIT bash

查看:223
本文介绍了在Windows安装的GIT bash中更改〜目录的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我甚至不确定我在问正确的问题。让我解释一下我的情况:

这是关于win7上的GIT的。

我的公司在不在本地硬盘上的网络驱动器上设置Windows用户目录(用于超出此问题范围的备份和其他目的)。我无法更改该政策。



我可以在该方案之外拥有本地文件,但这就是我的apache服务器的设置方式。完全是本地的。



我安装了GIT。它安装bash。当我启动bash和CD〜(切换到根目录)时,我发现它(bash root)指向我的网络用户目录。我希望不要这样做。我想〜在我的硬盘上的其他地方。我需要它,以便在执行其他操作时(例如安装证书,ssh密钥等),默认情况下不会自动使用该网络目录。



我已经搜索过在所有我能找到的地方都是徒劳的,指的是涉及别名,重定向,$ HOME指向的位置的答案。但那不是我想要的。



问题是:我可以更改那个目录吗?如果是这样的话:怎么做?



谢谢

更新:所以,$ HOME是我需要的修改。然而,我一直无法找到这个神话的$ HOME变量的设置,所以假设它是一个LINUX系统版本的PATH或其他东西。 ANYWAY ....



我在git / etc下有一个profile文件。这里是内容:(通知没有$ HOME)

 #尽可能根据法律,作者(s)有专门所有
#版权以及本软件对全球
#公共领域的相关和相邻权利。该软件的发布没有任何担保。
#您应该已经收到一份CC0 Public Domain Dedication的副本,此软件包含
#。
#如果没有,请参阅< http://creativecommons.org/publicdomain/zero/1.0/> ;.


#系统级配置文件

#一些资源...
#自定义您的Shell:http://www.dsl.org /cookbook/cookbook_5.html#SEC69
#一致的BackSpace和删除配置:
#http://www.ibb.net/~anne/keyboard.html
#Linux文档项目: http://www.tldp.org/
#Linux Cookbook:http://www.tldp.org/LDP/linuxcookbook/html/
#Greg's Wiki http://mywiki.wooledge。 org /

#设置一些默认路径。请注意,此订单将允许用户安装
#软件来覆盖系统软件。
#修改这些默认路径设置可以用不同的方式完成。
#要了解有关启动文件的更多信息,请参阅shell的手册页。

MSYS2_PATH =/ usr / local / bin:/ usr / bin:/ bin
MANPATH =/ usr / local / man:/ usr / share / man:/ usr / man:/ usr / share / info:/ usr / info:/ share / info:$ {INFOPATH}$ b $ INFPATH =/ usr / local / info:$ {MANPATH}
MINGW_MOUNT_POINT =
if [-n$ MSYSTEM]
然后
case $ MSYSTEM
MINGW32
MINGW_MOUNT_POINT = / mingw32
PATH =$ {MINGW_MOUNT_POINT} / bin:$ {MSYS2_PATH}:$ {PATH}
PKG_CONFIG_PATH =$ {MINGW_MOUNT_POINT} / lib / pkgconfig:$ {MINGW_MOUNT_POINT} / share / pkgconfig
ACLOCAL_PATH =$ {MINGW_MOUNT_POINT} / share / aclocal:/ usr / share / aclocal
MANPATH =$ {MINGW_MOUNT_POINT} / share / man:$ {MANPATH}
;;
MINGW64)
MINGW_MOUNT_POINT = / mingw64
PATH =$ {MINGW_MOUNT_POINT} / bin:$ {MSYS2_PATH}:$ {PATH}
PKG_CONFIG_PATH =$ {MINGW_MOUNT_POINT} / lib / pkgconfig:$ {MINGW_MOUNT_POINT} / share / pkgconfig
ACLOCAL_PATH =$ {MINGW_MOUNT_POINT} / share / aclocal:/ usr / share / aclocal
MANPATH =$ {MINGW_MOUNT_POINT} / share / man:$ {MANPATH}
;;
MSYS)
PATH =$ {MSYS2_PATH}:/ opt / bin:$ {PATH}
PKG_CONFIG_PATH =/ usr / lib / pkgconfig:/ usr / share / pkgconfig:/ lib / pkgconfig
;;
*)
PATH =$ {MSYS2_PATH}:$ {PATH}
;;
esac
else
PATH =$ {MSYS2_PATH}:$ {PATH}
fi

MAYBE_FIRST_START = false
SYSCONFDIR = $ {SYSCONFDIR:= / etc}

#即使从msys2启动,Windows环境中定义的TMP和TEMP也必须保留为
#。但是,如果将
#设置为默认的Windows临时目录或未设置
#,可能会给msys2应用程序带来意想不到的后果,所以我们定义
#以匹配GNU / Linux的行为。
ORIGINAL_TMP = $ TMP
ORIGINAL_TEMP = $ TEMP
#unset TMP TEMP
#tmp = $(cygpath -w$ ORIGINAL_TMP2> / dev / null)
#temp = $(cygpath -w$ ORIGINAL_TEMP2> / dev / null)
#TMP =/ tmp
#TEMP =/ tmp
case$ TMP in * \\ *)TMP =$(cygpath -m$ TMP);; esac
在* \\ *)TEMP =$(cygpath -m$ TEMP);; esac
test -d$ TMPDIR||测试! -d$ TMP|| {
TMPDIR =$ TMP
export TMPDIR
}


#定义默认打印机
p ='/ proc / registry / HKEY_CURRENT_USER / Software / Microsoft / Windows NT / CurrentVersion / Windows / Device'
if [-e$ {p}];然后
读取-r PRINTER< $ {p}
PRINTER = $ {PRINTER %%,*}
fi
unset p

print_flags()
{
(($ 1& 0x0002))&& echo -nbinary|| echo -ntext
(($ 1& 0x0010))&& echo -n,exec
(($ 1& 0x0040))&& echo -n,cygexec
(($ 1& 0x0100))&& echo -n,notexec


#shell依赖设置
profile_d()
{
本地文件=
$(export LC_COLLATE = C; echo /etc/profile.d/*.$1);做
[-e$ {file}]&& 。 $ {file}
完成

if [-n $ {MINGW_MOUNT_POINT}];然后
作为$(export LC_COLLATE = C; echo $ {MINGW_MOUNT_POINT} /etc/profile.d/*.$ 1);做
[-e$ {file}]&& 。 $ {file}
完成

}

用于postinst in $(export LC_COLLATE = C; echo /etc/post-install/*.post );做
[-e$ {postinst}]&& 。 $ {postinst}
完成

if [! x $ {BASH_VERSION}=x];然后
HOSTNAME =$(/ usr / bin / hostname)
profile_d sh
[-f/etc/bash.bashrc]&& 。 /etc/bash.bashrc
elif [! x $ {KSH_VERSION}=x];然后
typeset -l HOSTNAME =$(/ usr / bin / hostname)
profile_d sh
PS1 = $(print'\033] 0; $ {PWD} \\\
\033 [32m $ {USER} @ $ {HOSTNAME} \033 [33m $ {PWD / $ {HOME} /〜} \033 [0m\\\
$')
elif [! x $ {ZSH_VERSION}=x];然后
HOSTNAME =$(/ usr / bin / hostname)
profile_d zsh
PS1 ='(%n @%m)[%h]%〜%%'
elif [! x $ {POSH_VERSION}=x];然后
HOSTNAME =$(/ usr / bin / hostname)
PS1 =$
else
HOSTNAME =$(/ usr / bin / hostname)
profile_d sh
PS1 =$
fi

if [-n$ ACLOCAL_PATH]
然后
导出ACLOCAL_PATH
fi

export PATH MANPATH INFOPATH PKG_CONFIG_PATH USER TMP TEMP PRINTER HOSTNAME PS1 SHELL tmp temp
test -n$ TERM|| export TERM = xterm-256color

if [$ MAYBE_FIRST_START=true];那么
sh /usr/bin/regen-info.sh

如果[-f/ usr / bin / update-ca-trust]
然后
sh / usr / bin / update-ca-trust
fi

clear
echo
echo
echo######### ################################################## ########
echo##
echo##
echo#CAUTION#
echo##
回声#这是MSYS2的第一次启动#
echo#你必须重新启动shell才能应用必要的动作#
echo##
echo##
echo###################### #############################################
echo
echo
fi
unset MAYBE_FIRST_START


解决方案

我不明白,为什么你不想设置 $ HOME 环境变量,因为它完全解决了你要求的内容。



cd〜并不代表改为根目录,而是切换到由 $ HOME 环境变量设置的用户主目录





打开 C:\程序文件(x86)\Git\etc\profile 并将 $ HOME 变量设置为任何你想要的(如果它不存在,就添加它)。例如,在#设置USER的主目录的条件之后,一个好的地方就可以了。放在这里:

  HOME = / c / my / custom / home 

保存它,打开git-bash并执行 cd〜。您现在应该位于 / c / my / custom / home 目录中。



访问用户个人资料的所有内容应该进入此目录而不是网络驱动器上的Windows配置文件。



注意: C:\ Program Files(x86)\Git\etc\profile 被所有用户共享,所以如果机器被更多用户使用,最好将 $ HOME $ / code>动态:

  HOME = / c / Users / $ USERNAME 
code>


I am not even sure I am asking the right question. Let me explain my situation:

This is about GIT on win7.

My company sets up the Windows user directory on a network drive not on the local hard drive(for backup and other purposes beyond the scope of this question). I cannot change that policy.

I CAN have local files outside of that scheme however and that is how my apache server is set up. Entirely local.

I installed GIT. It installs bash. When I fire up bash and CD ~ (change to the root directory) I find that it(the bash root) points to my network user directory. I want it not to do that. I want ~ to be elsewhere on my hard drive. I want it so that when I perform other operations such as installing a certificate, a ssh key, etc. it's defaults will not automatically use that network directory.

I have searched in vain everywhere and all I can find refers to answers that involve aliases, redirection, the location $HOME points to. But that is not what I want at all.

The question is: Can I change that directory? and if so: How?

Thanks

UPDATE: So, $HOME is what I need to modify. However I have been unable to find where this mythical $HOME variable is set so a assumed the it was a LINUX system version of PATH or something. ANYWAY....

I do have a "profile" file under git/etc. Here are the contents: (notice no $HOME)

  # To the extent possible under law, the author(s) have dedicated all 
  # copyright and related and neighboring rights to this software to the 
  # public domain worldwide. This software is distributed without any warranty. 
  # You should have received a copy of the CC0 Public Domain Dedication along 
  # with this software. 
  # If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. 


  # System-wide profile file

  # Some resources...
  # Customizing Your Shell: http://www.dsl.org/cookbook/cookbook_5.html#SEC69
  # Consistent BackSpace and Delete Configuration:
  #   http://www.ibb.net/~anne/keyboard.html
  # The Linux Documentation Project: http://www.tldp.org/
  # The Linux Cookbook: http://www.tldp.org/LDP/linuxcookbook/html/
  # Greg's Wiki http://mywiki.wooledge.org/

  # Setup some default paths. Note that this order will allow user installed
  # software to override 'system' software.
  # Modifying these default path settings can be done in different ways.
  # To learn more about startup files, refer to your shell's man page.

  MSYS2_PATH="/usr/local/bin:/usr/bin:/bin"
  MANPATH="/usr/local/man:/usr/share/man:/usr/man:/share/man:${MANPATH}"
  INFOPATH="/usr/local/info:/usr/share/info:/usr/info:/share/info:${INFOPATH}"
  MINGW_MOUNT_POINT=
  if [ -n "$MSYSTEM" ]
  then
    case "$MSYSTEM" in
      MINGW32)
        MINGW_MOUNT_POINT=/mingw32
        PATH="${MINGW_MOUNT_POINT}/bin:${MSYS2_PATH}:${PATH}"
        PKG_CONFIG_PATH="${MINGW_MOUNT_POINT}/lib/pkgconfig:${MINGW_MOUNT_POINT}/share/pkgconfig"
        ACLOCAL_PATH="${MINGW_MOUNT_POINT}/share/aclocal:/usr/share/aclocal"
        MANPATH="${MINGW_MOUNT_POINT}/share/man:${MANPATH}"
      ;;
      MINGW64)
        MINGW_MOUNT_POINT=/mingw64
        PATH="${MINGW_MOUNT_POINT}/bin:${MSYS2_PATH}:${PATH}"
        PKG_CONFIG_PATH="${MINGW_MOUNT_POINT}/lib/pkgconfig:${MINGW_MOUNT_POINT}/share/pkgconfig"
        ACLOCAL_PATH="${MINGW_MOUNT_POINT}/share/aclocal:/usr/share/aclocal"
        MANPATH="${MINGW_MOUNT_POINT}/share/man:${MANPATH}"
      ;;
      MSYS)
        PATH="${MSYS2_PATH}:/opt/bin:${PATH}"
        PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/share/pkgconfig:/lib/pkgconfig"
      ;;
      *)
        PATH="${MSYS2_PATH}:${PATH}"
      ;;
    esac
  else
    PATH="${MSYS2_PATH}:${PATH}"
  fi

  MAYBE_FIRST_START=false
  SYSCONFDIR="${SYSCONFDIR:=/etc}"

  # TMP and TEMP as defined in the Windows environment must be kept
  # for windows apps, even if started from msys2. However, leaving
  # them set to the default Windows temporary directory or unset
  # can have unexpected consequences for msys2 apps, so we define 
  # our own to match GNU/Linux behaviour.
  ORIGINAL_TMP=$TMP
  ORIGINAL_TEMP=$TEMP
  #unset TMP TEMP
  #tmp=$(cygpath -w "$ORIGINAL_TMP" 2> /dev/null)
  #temp=$(cygpath -w "$ORIGINAL_TEMP" 2> /dev/null)
  #TMP="/tmp"
  #TEMP="/tmp"
  case "$TMP" in *\\*) TMP="$(cygpath -m "$TMP")";; esac
  case "$TEMP" in *\\*) TEMP="$(cygpath -m "$TEMP")";; esac
  test -d "$TMPDIR" || test ! -d "$TMP" || {
    TMPDIR="$TMP"
    export TMPDIR
  }


  # Define default printer
  p='/proc/registry/HKEY_CURRENT_USER/Software/Microsoft/Windows NT/CurrentVersion/Windows/Device'
  if [ -e "${p}" ] ; then
    read -r PRINTER < "${p}" 
    PRINTER=${PRINTER%%,*}
  fi
  unset p

  print_flags ()
  {
    (( $1 & 0x0002 )) && echo -n "binary" || echo -n "text"
    (( $1 & 0x0010 )) && echo -n ",exec"
    (( $1 & 0x0040 )) && echo -n ",cygexec"
    (( $1 & 0x0100 )) && echo -n ",notexec"
  }

  # Shell dependent settings
  profile_d ()
  {
    local file=
    for file in $(export LC_COLLATE=C; echo /etc/profile.d/*.$1); do
      [ -e "${file}" ] && . "${file}"
    done

    if [ -n ${MINGW_MOUNT_POINT} ]; then
      for file in $(export LC_COLLATE=C; echo ${MINGW_MOUNT_POINT}/etc/profile.d/*.$1); do
        [ -e "${file}" ] && . "${file}"
      done
    fi
  }

  for postinst in $(export LC_COLLATE=C; echo /etc/post-install/*.post); do
    [ -e "${postinst}" ] && . "${postinst}"
  done

  if [ ! "x${BASH_VERSION}" = "x" ]; then
    HOSTNAME="$(/usr/bin/hostname)"
    profile_d sh
    [ -f "/etc/bash.bashrc" ] && . "/etc/bash.bashrc"
  elif [ ! "x${KSH_VERSION}" = "x" ]; then
    typeset -l HOSTNAME="$(/usr/bin/hostname)"
    profile_d sh
    PS1=$(print '\033]0;${PWD}\n\033[32m${USER}@${HOSTNAME} \033[33m${PWD/${HOME}/~}\033[0m\n$ ')
  elif [ ! "x${ZSH_VERSION}" = "x" ]; then
    HOSTNAME="$(/usr/bin/hostname)"
    profile_d zsh
    PS1='(%n@%m)[%h] %~ %% '
  elif [ ! "x${POSH_VERSION}" = "x" ]; then
    HOSTNAME="$(/usr/bin/hostname)"
    PS1="$ "
  else 
    HOSTNAME="$(/usr/bin/hostname)"
    profile_d sh
    PS1="$ "
  fi

  if [ -n "$ACLOCAL_PATH" ]
  then
    export ACLOCAL_PATH
  fi

  export PATH MANPATH INFOPATH PKG_CONFIG_PATH USER TMP TEMP PRINTER HOSTNAME PS1 SHELL tmp temp
  test -n "$TERM" || export TERM=xterm-256color

  if [ "$MAYBE_FIRST_START" = "true" ]; then
    sh /usr/bin/regen-info.sh

    if [ -f "/usr/bin/update-ca-trust" ]
    then 
      sh /usr/bin/update-ca-trust
    fi

    clear
    echo
    echo
    echo "###################################################################"
    echo "#                                                                 #"
    echo "#                                                                 #"
    echo "#                   C   A   U   T   I   O   N                     #"
    echo "#                                                                 #"
    echo "#                  This is first start of MSYS2.                  #"
    echo "#       You MUST restart shell to apply necessary actions.        #"
    echo "#                                                                 #"
    echo "#                                                                 #"
    echo "###################################################################"
    echo
    echo
  fi
  unset MAYBE_FIRST_START

解决方案

I don't understand, why you don't want to set the $HOME environment variable since that solves exactly what you're asking for.

cd ~ doesn't mean change to the root directory, but change to the user's home directory, which is set by the $HOME environment variable.

I just tested it and it works for me:

Open C:\Program Files (x86)\Git\etc\profile and set $HOME variable to whatever you want (add it if it's not there). A good place could be for example right after a condition commented by # Set up USER's home directory. Put there something like this:

HOME=/c/my/custom/home

Save it, open git-bash and execute cd ~. You should be in a directory /c/my/custom/home now.

Everything that accesses the user's profile should go into this directory instead of your Windows' profile on a network drive.

Note: C:\Program Files (x86)\Git\etc\profile is shared by all users, so if the machine is used by more users, it's a good idea to set the $HOME dynamically:

HOME=/c/Users/$USERNAME

这篇关于在Windows安装的GIT bash中更改〜目录的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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