适用于 Windows 的 Git 不执行我的 .bashrc 文件

     2023-03-13     162

关键词:

【中文标题】适用于 Windows 的 Git 不执行我的 .bashrc 文件【英文标题】:Git for Windows doesn't execute my .bashrc file 【发布时间】:2015-11-18 03:28:12 【问题描述】:

我刚刚在 Windows 7 上安装了适用于 Windows 2.5.0 的 Git,当我运行 Git Bash 时,我的 .bashrc 文件似乎没有被执行。

我是这样创建文件的:

Administrator@HintTech-Dev MINGW64 /
$ pwd
/

Administrator@HintTech-Dev MINGW64 /
$ cd ~

Administrator@HintTech-Dev MINGW64 ~
$ pwd
/c/Users/Administrator

Administrator@HintTech-Dev MINGW64 ~
$ touch .bashrc

Administrator@HintTech-Dev MINGW64 ~
$ vi .bashrc

[... I insert the line "ZZZTESTVAR=234" (without the quotes) into the file in vim ...]

Administrator@HintTech-Dev MINGW64 ~
$ exit

然而,当我下次运行 Git Bash 时:

Administrator@HintTech-Dev MINGW64 /
$ set | grep ZZZ

Administrator@HintTech-Dev MINGW64 /
$ cat ~/.bashrc
ZZZTESTVAR=234

Administrator@HintTech-Dev MINGW64 /
$ ZZZTESTVAR=234

Administrator@HintTech-Dev MINGW64 /
$ set | grep ZZZ
ZZZTESTVAR=234

Administrator@HintTech-Dev MINGW64 /
$

为什么我的.bashrc 没有运行?它似乎在正确的位置并具有正确的权限。

【问题讨论】:

我正在运行 Git bash 版本 1.9.5-preview20150319 并运行了与您运行的完全相同的测试,但对我来说,它有效。我的.bashrc 运行了。变量被设置。你有.profile.bash_profile 吗?这些将阻止 .bashrc 运行。 不,我什至没有.profile.bash_profile。但是您使用的是适用于 Windows 2.5.0 的 Git 吗? 【参考方案1】:

好的,我发现了问题。很简单,最新的 Git for Windows 2.5.0 (mintty) 使用的 bash 终端不需要阅读 .bashrc - 它会阅读 .bash_profile。因此,您可以在.bash_profile 中设置您的环境和/或将此代码放在开头以阅读.bashrc

if [ -f ~/.bashrc ]
then
    . ~/.bashrc
fi

【讨论】:

这不是薄荷本身,而是 git-bash.exe 如何启动它。在这里进行了长时间的讨论,基本上以更改安装程序以创建 .bash_profile 为结束,就像您描述的那样:github.com/git-for-windows/git/issues/191 解决方案今天 2020 年 5 月在 Windows 10 git bash 上仍然有效【参考方案2】:

当我在 Windows 10 中升级到 Git Bash 2.5.0 时,我也发生了同样的事情。我重命名了我的 '.bashrc' -> '.bash_profile' 并重新启动了 Git Bash。一切都恢复正常了。

mv ~/.bashrc ~/.bash_profile

【讨论】:

这与上面的几乎相同,但它们都很好用 小心不要覆盖你的 conda .bash_profile【参考方案3】:

似乎最新版本的 git for Windows (2.8.3.windows.1) 现在使用“配置文件”文件而不是 .bash_profile。我认为这是因为它不是隐藏的并且是有效的文件名。以前似乎没有引起任何问题,但可能会让人感到困惑。

【讨论】:

【参考方案4】:

这个答案可能有点晚了,但您可以使用 -rcfile 参数调用 bash,后跟 .bashrc 文件的位置。

bash -rcfile C:\Users\name\.bashrc

我已将此添加到我的 PowerShell 配置文件(.ps1 文件)的末尾,以便 Powershell 自动在 bash 中打开并根据我的偏好进行配置。

【讨论】:

mintty 没有参数 -rcfile,这就是为什么 mintty 需要 .bash_profile

Git:使用适用于 Windows 的 GitHub 客户端在 PATH 中安装 Git

】Git:使用适用于Windows的GitHub客户端在PATH中安装Git【英文标题】:Git:InstallingGitinPATHwithGitHubclientforWindows【发布时间】:2014-12-2413:33:19【问题描述】:使用Windows的GitHub客户端时,如何在我的PATH中安装Git?我遇到了错误,因为显... 查看详情

适用于 Linux 的 Windows 子系统 git mergetool meld UnicodeDecodeError

】适用于Linux的Windows子系统gitmergetoolmeldUnicodeDecodeError【英文标题】:WindowsSubsystemforLinuxgitmergetoolmeldUnicodeDecodeError【发布时间】:2019-01-0913:59:21【问题描述】:我是WSL(适用于Linux的Windows子系统)用户。我使用WSL在我的主机和远... 查看详情

如何禁用适用于 Windows 的 Git 凭据管理器?

】如何禁用适用于Windows的Git凭据管理器?【英文标题】:HowdoIdisableGitCredentialManagerforWindows?【发布时间】:2016-09-0801:08:48【问题描述】:我注意到,在最新版本的Git中,现在默认是弹出“Windows版Git凭据管理器”对话框,而不是... 查看详情

如何使用适用于 Windows 的 Git 更改 Git Bash 中的目录?

】如何使用适用于Windows的Git更改GitBash中的目录?【英文标题】:HowdoIchangethedirectoryinGitBashwithGitforWindows?【发布时间】:2013-08-1918:28:15【问题描述】:如何在GitBash中切换到目录C:/Users/myname/projectname?【问题讨论】:cd\'THAT_DIRECTORY... 查看详情

在 Windows 容器内运行 git bash

】在Windows容器内运行gitbash【英文标题】:rungitbashinsidewindowscontainer【发布时间】:2019-01-0506:49:29【问题描述】:我在我的容器中安装了适用于Windows的Git和gitbash。当我执行它并尝试运行sh.exe或bash.exe时,它​​看起来像是尝试打... 查看详情

从适用于 Windows 10 的 Git Bash 隐藏用户名和计算机名称

】从适用于Windows10的GitBash隐藏用户名和计算机名称【英文标题】:HideusernameandcomputernamefromGitBashforWindows10【发布时间】:2018-06-0907:38:02【问题描述】:有没有办法从GitBashforWindow10中删除用户名和计算机名?我已经检查过了:https:... 查看详情

适用于 Windows 的 Git-scm、msysGit 和 Git 之间的区别

】适用于Windows的Git-scm、msysGit和Git之间的区别【英文标题】:DifferencesbetweenGit-scm,msysGit&GitforWindows【发布时间】:2014-04-1403:17:24【问题描述】:git-scm(从git-scm.com下载)和msysGit(托管在GoogleCode、Github和可能的其他服务器上)... 查看详情

sh适用于windows的git:文件名太长(代码片段)

查看详情

适用于 Windows 的 OpenAcc

】适用于Windows的OpenAcc【英文标题】:OpenAccforWindows【发布时间】:2016-09-1914:15:39【问题描述】:使用VisualStudio,我能够在配备geforcegtx560tiGPU的工作站上构建和执行使用CUDA的C++代码。我还从NVIDIA开发者网站下载了OpenACC工具包,我... 查看详情

适用于 Windows 的 Git:Git\bin\bash.exe 和 Git\usr\bin\bash.exe 之间的区别

】适用于Windows的Git:Git\\\\bin\\\\bash.exe和Git\\\\usr\\\\bin\\\\bash.exe之间的区别【英文标题】:GitforWindows:DifferencebetweenGit\\bin\\bash.exeandGit\\usr\\bin\\bash.exe适用于Windows的Git:Git\\bin\\bash.exe和Git\\usr\\bin\\bash.exe之间的区别【发布 查看详情

适用于 Windows 7 的 Git 无法从 github 克隆存储库

】适用于Windows7的Git无法从github克隆存储库【英文标题】:Gitforwindows7failingtoclonetherepofromgithub【发布时间】:2016-08-2420:19:55【问题描述】:我有gitrepohttps://github.com/jcubic/jquery.terminal我正在使用linuxbox(Xubuntu)使用它,它工作正常,... 查看详情

适用于 Windows 的 PhpStorm 和 Github

】适用于Windows的PhpStorm和Github【英文标题】:PhpStormandGithubforWindows【发布时间】:2012-09-1211:39:25【问题描述】:PhpStorm与Git的集成要求我提供git.exe路径,但是“githubforwindows”似乎没有创建任何git.exe文件。那么它是一种配置phpstor... 查看详情

带有 ssh 的 Git 克隆适用于 Linux,但不适用于 Windows PowerShell

】带有ssh的Git克隆适用于Linux,但不适用于WindowsPowerShell【英文标题】:GitclonewithsshworksinLinuxbutnotinWindowsPowerShell【发布时间】:2021-01-0710:38:37【问题描述】:我在GitHub上有一个仓库。在Linux中使用ssh克隆它时效果很好:>gitclonegi... 查看详情

适用于 Windows 的 NVM 无法正常工作?

】适用于Windows的NVM无法正常工作?【英文标题】:NVMforWindowsnotworking?【发布时间】:2015-04-0312:03:25【问题描述】:我刚刚安装了NVMforWindows,但它似乎不起作用:有什么想法吗?【问题讨论】:之后打开一个新的命令提示符并执... 查看详情

获取适用于 Windows 的 SubVersion 1.4 可执行文件

】获取适用于Windows的SubVersion1.4可执行文件【英文标题】:ObtainSubVersion1.4executablesforWindows【发布时间】:2010-03-3101:53:42【问题描述】:我需要使用一个旧的存储库,其db/format包含2来自thisquestion,我了解到这意味着它是1.4版。我... 查看详情

适用于 Android 的 OkHttp:不强制执行证书/公钥固定的选项

】适用于Android的OkHttp:不强制执行证书/公钥固定的选项【英文标题】:OkHttpforAndroid:OptiontoNOTenforceCertificate/publickeypinning【发布时间】:2020-04-0921:24:08【问题描述】:我在我的SDK中使用Okhttp+Retrofit进行网络连接。我需要实施证书... 查看详情

适用于 Windows 7 32 位系统的 Java 11 JDK

】适用于Windows732位系统的Java11JDK【英文标题】:Java11JDKforWindows732-bitsystem【发布时间】:2022-01-1011:55:53【问题描述】:我想在我的Windows32位系统上安装Java11。我搜索过thisOfficialJava11DownloadPage不包含任何32位系统的下载。但我还是... 查看详情

是否有适用于 Windows 的 JSLint 的离线版本?

】是否有适用于Windows的JSLint的离线版本?【英文标题】:IsthereanofflineversionofJSLintforWindows?【发布时间】:2010-09-1815:03:40【问题描述】:我想在不访问JSLint网站的情况下检查我的JavaScript文件。此工具是否有适用于Windows的桌面版本... 查看详情