Ich bin nicht einmal sicher, ob ich die richtige Frage stelle. Lassen Sie mich meine Situation erklären:
Hier geht es um Git unter Windows 7.
Meine Firma richtet das Windows-Benutzerverzeichnis auf einem Netzlaufwerk und nicht auf der lokalen Festplatte ein (für Backups und andere Zwecke, die über diese Frage hinausgehen). Ich kann diese Politik nicht ändern.
Ich kann jedoch lokale Dateien außerhalb dieses Schemas haben, und so ist mein Apache-Server eingerichtet. Ganz lokal.
Ich habe Git installiert. Es installiert Bash. Wenn ich Bash und cd ~
(wechsle in das Stammverzeichnis) starte, stelle ich fest, dass es (das Bash-Stammverzeichnis) auf mein Netzwerkbenutzerverzeichnis verweist. Ich will das nicht tun. Ich möchte, dass ~
anderswo auf meiner Festplatte ist. Ich möchte, dass bei der Ausführung anderer Vorgänge wie dem Installieren eines Zertifikats, eines SSH-Schlüssels usw. dessen Standardeinstellungen dieses Netzwerkverzeichnis nicht automatisch verwenden.
Ich habe überall vergeblich gesucht, und alles, was ich finden kann, bezieht sich auf Antworten, die Aliase, Umleitung und die Position beinhalten, auf die $ HOME verweist. Aber das will ich überhaupt nicht.
Die Frage ist: Kann ich dieses Verzeichnis ändern? Und wenn ja: wie?
UPDATE: Also, $ HOME muss ich ändern. Ich konnte jedoch nicht herausfinden, wo diese mythische $ HOME-Variable festgelegt ist, also nahm ich an, dass es sich um eine Linux-Systemversion von PATH oder etwas anderes handelt. Sowieso...
Ich habe eine "Profil" -Datei unter git/etc
. Hier sind die Inhalte (keine $ HOME beachten):
# 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='(%[email protected]%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
Ich verstehe nicht, warum Sie die Umgebungsvariable $HOME
nicht festlegen möchten, da dadurch genau das gelöst wird, wonach Sie fragen.
cd ~
bedeutet nicht wechselt in das Stammverzeichnis, sondern wechselt in das Home-Verzeichnis des Benutzers , das durch die Umgebungsvariable $HOME
festgelegt wird.
Ich habe es gerade getestet und es funktioniert für mich:
Öffnen Sie C:\Program Files (x86)\Git\etc\profile
und setzen Sie die Variable $HOME
auf das, was Sie möchten (fügen Sie es hinzu, wenn es nicht vorhanden ist). Ein guter Ort könnte zum Beispiel direkt nach einer von # Set up USER's home directory
kommentierten Bedingung sein. Geben Sie dort etwas wie folgt ein:
HOME=/c/my/custom/home
Speichern Sie es, öffnen Sie git-bash und führen Sie cd ~
aus. Sie sollten sich jetzt in einem Verzeichnis /c/my/custom/home
befinden.
Alles, was auf das Benutzerprofil zugreift, sollte in dieses Verzeichnis gehen, anstatt auf einem Netzlaufwerk Ihr Windows-Profil.
Hinweis: C:\Program Files (x86)\Git\etc\profile
wird von allen Benutzern gemeinsam genutzt. Wenn der Computer von mehreren Benutzern verwendet wird, empfiehlt es sich, den $HOME
dynamisch einzustellen:
HOME=/c/Users/$USERNAME
Ich sehe, dass diese Frage bereits beantwortet ist, aber ich bin in einer ähnlichen Situation, und ich dachte, ich würde teilen, was ich getan habe. Ich habe das ursprünglich nicht für Git gemacht, sondern für MSYS/MinGW.
Die Umgebungsvariable HOME
ist normalerweise nicht für Windows-Anwendungen festgelegt. Das Erstellen über Windows hat jedoch nichts beeinflusst, was nicht betroffen sein sollte. Wählen Sie in den Computereigenschaften (mit der rechten Maustaste im Explorer auf Computer - oder wie auch immer er bezeichnet wird - und wählen Sie Eigenschaften oder Systemsteuerung -> System und Sicherheit -> System). Wählen Sie Advanced system settings
, dann Evironment Variables...
und erstellen Sie eine neue Variable, HOME
. und ordnen Sie es zu, wo Sie möchten.
Wenn Sie keine neuen Umgebungsvariablen erstellen können, funktioniert die andere Antwort weiterhin. (Ich habe die Details zum Erstellen von Umgebungsvariablen genau durchgesehen, weil sie so schwer zu finden sind.)
In meinem Fall musste ich lediglich die folgende User-Variable unter Windows hinzufügen:
Variablenname: HOME
Variablenwert: %USERPROFILE%
So stellen Sie eine Umgebungsvariable ein (Sie können die User-Variablen für den Benutzernamen verwenden, wenn Sie kein Systemadministrator sind.)
Anstatt das globale profile
zu ändern, können Sie das .bash_profile
in Ihrem Standardverzeichnis $HOME
(z. B. C:\Users\WhateverUser\.bash_profile
) mit folgendem Inhalt erstellen:
export HOME="C:\my\projects\dir"
cd "$HOME" # if you'd like it to be the starting dir of the git Shell
1.Klicken Sie mit der rechten Maustaste auf die Gitbash-Verknüpfung, und wählen Sie Eigenschaften
2. Wählen Sie die Registerkarte "Verknüpfung"
3. Geben Sie Ihr Startverzeichnis in das Feld "Start in" ein
4. Entfernen Sie den Teil "--cd-to-home" aus dem Feld "Target"
Also, $ HOME muss ich ändern. Ich konnte jedoch nicht herausfinden, wo diese mythische $ HOME-Variable festgelegt ist, also nahm ich an, dass es sich um eine Linux-Systemversion von PATH oder etwas anderes handelt. Sowieso ...**
Das Hinzufügen von HOME am Anfang der Datei profile
hat funktioniert.
HOME="c://path/to/custom/root/"
.
#THE FIX WAS ADDING THE FOLLOWING LINE TO THE TOP OF THE PROFILE FILE
HOME="c://path/to/custom/root/"
# below are the original contents ===========
# To the extent possible under law, ..blah blah
# 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='(%[email protected]%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
Ich hatte genau das gleiche Problem. Mein Heimlaufwerk ist einem Netzlaufwerk zugeordnet. Ebenfalls 1. Nein Schreibzugriff auf das Heimatlaufwerk 3. Kein Schreibzugriff auf das Git-Bash-Profil 4. Keine Administratorrechte zum Ändern von Umgebungsvariablen über das Bedienfeld.
Unten jedoch funktionierte die Befehlszeile und ich konnte Umgebungsvariablen mit HOME
versehen.
rundll32 sysdm.cpl,EdtEnvironmentVariables
Also muss ich
$HOME
ändern.Ich konnte jedoch nicht herausfinden, wo diese mythische
$HOME
-Variable gesetzt ist, und nahm daher an, dass es sich um eine Linux-Systemversion von PATH oder so handelt.
Git 2.23 (Q3 2019) ist ziemlich explizit, wie HOME
eingestellt wird.
Siehe commit e12a955 (04. Juli 2019) von Karsten Blees (kblees
) .
(Zusammengeführt von Junio C Hamano - gitster
- in Commit fc613d2 , 19. Juli 2019)
mingw: HOME beim Start initialisieren
Die
HOME
-Initialisierung wurde historisch an vielen verschiedenen Stellen dupliziert, einschließlich/etc/profile
, Startskripten wiegit-bash.vbs
undgitk.cmd
(obwohl geringfügig unterbrochen) ingit-wrapper
. .Selbst nicht verwandte Projekte wie
GitExtensions
undTortoiseGit
müssen dieselbe Logik implementieren, um git direkt aufrufen zu können.Initialisieren Sie
HOME
in Gits eigenem Startcode, damit wir eventuell den gesamten duplizierten Initialisierungscode zurückziehen können.
Nun enthält mingw.c den folgenden Code:
/* calculate HOME if not set */ if (!getenv("HOME")) { /* * try $HOMEDRIVE$HOMEPATH - the home share may be a network * location, thus also check if the path exists (i.e. is not * disconnected) */ if ((tmp = getenv("HOMEDRIVE"))) { struct strbuf buf = STRBUF_INIT; strbuf_addstr(&buf, tmp); if ((tmp = getenv("HOMEPATH"))) { strbuf_addstr(&buf, tmp); if (is_directory(buf.buf)) setenv("HOME", buf.buf, 1); else tmp = NULL; /* use $USERPROFILE */ } strbuf_release(&buf); } /* use $USERPROFILE if the home share is not available */ if (!tmp && (tmp = getenv("USERPROFILE"))) setenv("HOME", tmp, 1); }