我什至不确定我问的是正确的问题。先说明一下我的情况:
这是关于 Windows 7 上的 Git。
我的公司在网络驱动器上设置 Windows 用户目录,而不是在本地硬盘驱动器上(用于备份和超出此问题范围的其他目的)。我不能改变那个政策。
但是,我可以在该方案之外拥有本地文件,这就是我的 Apache 服务器的设置方式。完全本地化。
我安装了 Git。它安装 Bash。当我启动 Bash 并cd ~(更改到根目录)时,我发现它(Bash 根目录)指向我的网络用户目录。我希望它不要那样做。我想 ~在我的硬盘驱动器上的其他地方。我想要它,这样当我执行其他操作(例如安装证书、SSH 密钥等)时,它的默认值不会自动使用该网络目录。
cd ~
~
我到处搜索都是徒劳的,我能找到的只是涉及别名、重定向和 $HOME 指向的位置的答案。但这根本不是我想要的。
问题是:我可以更改该目录吗?如果是这样:如何?
更新:所以, $HOME 是我需要修改的。 但是我一直无法找到这个神秘的 $HOME 变量的设置位置,所以我认为它是 PATH 的 Linux 系统版本或其他东西。 反正…
我确实有一个“个人资料”文件git/etc。以下是内容(注意没有 $HOME):
git/etc
# 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
我不明白,为什么您不想设置$HOME环境变量,因为这完全可以解决您的要求。
$HOME
cd ~不是 切换到根目录 ,而是 切换到用户的主目录 ,由$HOME环境变量设置。
编辑C:\Program Files (x86)\Git\etc\profile并将$HOME变量设置为您想要的任何内容(如果它不存在,请添加它)。例如,一个好地方可能是在 评论的条件之后# Set up USER's home directory。它必须是 MinGW 格式,例如:
C:\Program Files (x86)\Git\etc\profile
# Set up USER's home directory
HOME=/c/my/custom/home
保存它,打开 Git Bash 并执行cd ~. 您现在应该在一个目录中/c/my/custom/home。
/c/my/custom/home
访问用户配置文件的所有内容都应进入此目录,而不是网络驱动器上的 Windows 配置文件。
注意: C:\Program Files (x86)\Git\etc\profile是所有用户共享的,所以如果机器被多个用户使用,最好$HOME动态设置:
HOME=/c/Users/$USERNAME
将 Windows 中的环境变量设置为HOME您想要的任何目录。在这种情况下,您必须将其设置为 Windows 路径格式(带有反斜杠,例如c:\my\custom\home),Git Bash 将加载它并将其转换为它的格式。
HOME
c:\my\custom\home
如果要 更改计算机上所有用户的主目录 ,请将其设置为 系统环境变量 ,您可以在其中使用例如%USERNAME%变量,以便每个用户都有自己的主目录,例如:
%USERNAME%
HOME=c:\custom\home\%USERNAME%
如果你想 只为自己更改主目录 ,请将其设置为 用户环境变量 ,这样其他用户就不会受到影响。在这种情况下,您可以简单地对整个路径进行硬编码:
HOME=c:\my\custom\home