启动 GitBash 时未执行 .bashrc
.bashrc not executed when starting GitBash
我正在关注 this guide, I've gotten to the part where I need to create the .bashrc file and it doesn't seem to execute when I restart GitBash. I've tried a few things including the answers on this SO question。我也试过只在其中添加一个回声进行测试,当我直接执行它时它会起作用,但当我启动 GitBash 时却不起作用。
首先,确保使用最新的Git:
- 未压缩
PortableGit-2.5.0-64-bit.7z.exe
任何你想要的地方,并将 C:\path\to\PortableGit-2.5.0-64-bit\bin 添加到你的 %PATH%
.
- 然后更新您的
%USERPROFILE%\.bashrc
- 最后,启动
C:\path\to\PortableGit-2.5.0-64-bit\git-bash.exe
如果您在修改 .bashrc 时已经在 bash 会话中,请再次获取它以查看它是否执行您需要的内容。
source .bashrc
我通过执行 git-bash -l -c bash
解决了这个问题(-l 是小写的 L)。
这样我的 $HOME/.bashrc 就会立即执行。
我在 Windows 7.
上使用 PortableGit 2.5.0
从 Git 2.5.0 开始,.bashrc 似乎不再引用 %USERPROFILE%\.bashrc。
但是你可以编辑这个文件:“C:\Program Files\Git\etc\bash.bashrc”。这是一个全局文件,但它必须这样做。
此外,我认为建议编辑位于“C:\Program Files\Git\etc\profile.d”的文件,而不是创建 .bashrc。
该文件夹中的文件如下所示:
Some good standards, which are not used if the user
creates his/her own .bashrc/.bash_profile
默认情况下 ~/.bashrc
不是来源,但 ~/.profile
是...
您只需创建一个 ~/.profile
来源您的 ~/.bashrc
下面是我的 cygwin 附带的 ~/.profile,我复制到我的 git-bash 的 ~.
# 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/>.
# base-files version 4.2-4
# ~/.profile: executed by the command interpreter for login shells.
# The latest version as installed by the Cygwin Setup program can
# always be found at /etc/defaults/etc/skel/.profile
# Modifying /etc/skel/.profile directly will prevent
# setup from updating it.
# The copy in your home directory (~/.profile) is yours, please
# feel free to customise it to create a shell
# environment to your liking. If you feel a change
# would be benificial to all, please feel free to send
# a patch to the cygwin mailing list.
# User dependent .profile file
# Set user-defined locale
export LANG=$(locale -uU)
# This file is not read by bash(1) if ~/.bash_profile or ~/.bash_login
# exists.
#
# if running bash
if [ -n "${BASH_VERSION}" ]; then
if [ -f "${HOME}/.bashrc" ]; then
source "${HOME}/.bashrc"
fi
fi
默认 git-bash 与 Win10 上的 mingw64 似乎不是来源 .bash_rc
和 .profile
.
改用.bash_profile
。
原题(和本站通过link提供)讲ssh-agent
。通过 echo 'kill -KILL $SSH_AGENT_PID' >> .bash_logout
在 git-bash 退出时清理代理是个好主意。 git-bash 似乎使这些代理 运行 跨会话保留,但无法再访问它们,因为变量已经消失。 .bash_logout
来源于 git-bash
在 Win10 机器上测试 $git version
给出 git version 2.20.1.windows.1
我正在关注 this guide, I've gotten to the part where I need to create the .bashrc file and it doesn't seem to execute when I restart GitBash. I've tried a few things including the answers on this SO question。我也试过只在其中添加一个回声进行测试,当我直接执行它时它会起作用,但当我启动 GitBash 时却不起作用。
首先,确保使用最新的Git:
- 未压缩
PortableGit-2.5.0-64-bit.7z.exe
任何你想要的地方,并将 C:\path\to\PortableGit-2.5.0-64-bit\bin 添加到你的%PATH%
. - 然后更新您的
%USERPROFILE%\.bashrc
- 最后,启动
C:\path\to\PortableGit-2.5.0-64-bit\git-bash.exe
如果您在修改 .bashrc 时已经在 bash 会话中,请再次获取它以查看它是否执行您需要的内容。
source .bashrc
我通过执行 git-bash -l -c bash
解决了这个问题(-l 是小写的 L)。
这样我的 $HOME/.bashrc 就会立即执行。
我在 Windows 7.
从 Git 2.5.0 开始,.bashrc 似乎不再引用 %USERPROFILE%\.bashrc。
但是你可以编辑这个文件:“C:\Program Files\Git\etc\bash.bashrc”。这是一个全局文件,但它必须这样做。
此外,我认为建议编辑位于“C:\Program Files\Git\etc\profile.d”的文件,而不是创建 .bashrc。
该文件夹中的文件如下所示:
Some good standards, which are not used if the user
creates his/her own .bashrc/.bash_profile
~/.bashrc
不是来源,但 ~/.profile
是...
您只需创建一个 ~/.profile
来源您的 ~/.bashrc
下面是我的 cygwin 附带的 ~/.profile,我复制到我的 git-bash 的 ~.
# 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/>.
# base-files version 4.2-4
# ~/.profile: executed by the command interpreter for login shells.
# The latest version as installed by the Cygwin Setup program can
# always be found at /etc/defaults/etc/skel/.profile
# Modifying /etc/skel/.profile directly will prevent
# setup from updating it.
# The copy in your home directory (~/.profile) is yours, please
# feel free to customise it to create a shell
# environment to your liking. If you feel a change
# would be benificial to all, please feel free to send
# a patch to the cygwin mailing list.
# User dependent .profile file
# Set user-defined locale
export LANG=$(locale -uU)
# This file is not read by bash(1) if ~/.bash_profile or ~/.bash_login
# exists.
#
# if running bash
if [ -n "${BASH_VERSION}" ]; then
if [ -f "${HOME}/.bashrc" ]; then
source "${HOME}/.bashrc"
fi
fi
默认 git-bash 与 Win10 上的 mingw64 似乎不是来源 .bash_rc
和 .profile
.
改用.bash_profile
。
原题(和本站通过link提供)讲ssh-agent
。通过 echo 'kill -KILL $SSH_AGENT_PID' >> .bash_logout
在 git-bash 退出时清理代理是个好主意。 git-bash 似乎使这些代理 运行 跨会话保留,但无法再访问它们,因为变量已经消失。 .bash_logout
来源于 git-bash
在 Win10 机器上测试 $git version
给出 git version 2.20.1.windows.1