ift*_*itz 230 windows git git-bash
我刚刚安装了Git for Windows,很高兴看到它安装了Bash.
我想以与Linux相同的方式自定义shell(例如设置类似ll的别名ls -l),但我似乎无法找到.bashrc或等效的配置文件.
我该怎么编辑?
Cha*_* Ma 283
.bashrc在~/.bashrc你下面创建一个文件.同样的~/.gitconfig.
~通常是你的C:\Users\<your user name>文件夹.键入echo ~在Git的Bash的终端会告诉你该文件夹是什么.
如果无法创建文件(例如运行Windows),请运行以下命令:
copy > ~/.bashrc
该窗口将输出错误消息(未找到命令),但该文件将被创建并准备好供您编辑.
har*_*sel 100
在较新版本的Git for Windows中,Bash启动时--login会导致Bash无法.bashrc直接读取.相反,它读取.bash_profile.
如果此文件不存在,请使用以下内容创建它:
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
这将导致Bash读取.bashrc文件.根据我对这个问题的理解,Git for Windows应该自动执行此操作.但是,我刚刚安装了2.5.1版,但事实并非如此.
Sur*_*ran 16
请使用以下命令,
cat /etc/bash.bashrc > ~/.bashrc
这将生成一个具有默认值的新 bashrc 文件。请使用vi ~/.bashrc编辑此文件。    
Aya*_*yan 10
只需notepad ~/.bashrc从 git bash shell 并保存文件即可。这应该就是全部了。
注意:请确保您需要重新启动终端才能反映更改。
我不得不添加一个用户环境变量HOME,以C:\Users\<your user name>通过将系统,高级系统设置,在系统属性窗口,在高级选项卡,环境变量 ...
然后在我中C:\Users\<your user name>创建文件.bashrc,例如,touch .bashrc并添加所需的别名。
小智 7
1) 首先在管理员模式下打开 git-bash.exe。(右键单击该文件并选择“以管理员身份运行”,或在“属性”→“兼容性”→“以管理员身份运行此程序”中更改设置。)
2)运行cd ~。它会带你去C:/Users/<Your-Username>。
3)运行vi .bashrc。这将打开您进入编辑器。点击 INSERT,然后开始输入以下信息:
alias ll="ls -la" # this changes the default ll on git bash to see hidden files.
cd "C:\directory\to\your\work\path\"
ll # this shows your your directory before you even type anything.
我认为这里的问题是如何在Windows上找到.bashrc文件。
由于您使用的是Windows,因此您可以简单地使用以下命令
start .
要么
explorer .
打开包含您的Git Bash安装目录的根目录的窗口.bashrc。如果不存在,则可能需要创建一个。
您可以使用Windows Notepad ++之类的Windows工具来编辑文件,而不是在Bash窗口中使用Vim。
转到:C:\Program Files\Git\etc\profile.d,在里面你可以找到你需要的一切。
或者在您的主目录中创建 .bashrc 和 .bash_profile。
.bash_配置文件
# generated by Git for windows
test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc
.bashrc
echo "Hello World!"