参考:https://qastack.cn/superuser/602872/how-do-i-modify-my-git-bash-profile-in-windows
我在Windows 7上使用Git Bash,并希望设置Bash配置文件别名,例如alias gs='git status'
使我的生活更轻松。我怎样才能做到这一点?
Answers:
当您打开Git Bash时,默认情况下您应该位于主目录中。现在创建.bashrc文件(如果在Windows 7上,该文件应命名为.bashrc。)。
如果您不在主目录中,请输入以下内容更改为主目录:
光盘
然后按Enter。cd,后面没有列出任何其他参数,将始终返回主目录。
您可以通过键入以下内容来创建文件:
触摸.bashrc
然后使用Vim编辑它,或者您可以尝试使用Windows编辑器进行编辑,但是由于某些文本格式问题,我不建议这样做。
vim .bashrc
通过i按键更改为插入模式。
通过输入以下内容添加别名:
别名gs ='git status'
Esc按下键退出插入模式。
通过键入以下命令保存并关闭文件:wqEnter。
:wEnter 只会保存您的文件。
:q!Enter 将退出编辑器而不保存文件。
最后,通过键入以下内容来更新文件以使用您的新更改:
源.bashrc
WARNING: Found ~/.bashrc but no ~/.bash_profile, ~/.bash_login or ~/.profile. This looks like an incorrect setup. A ~/.bash_profile that loads ~/.bashrc will be created for you.
(Git-2.11.0-64位)
touch
文件,
vi
将直接为您创建文件。防止您排队;)
您可以放入.bash_profile
用户目录:C:\ Users \ <用户名>。
您还可以创建一些混帐仅别名,所以你可以做git st
的git status
,加入这些行C:\ Users \ <用户名> \ gitconfig。 :
[alias] st = status
其他一些有用的别名:
cm = commit -m cma = commit -a -m br = branch co = checkout df = diff ls = ls-files sh = stash sha = stash apply shp = stash pop shl = stash list mg = merge ph = push -u
.gitconfig
则通常只需编辑文件即可。
.bash_profile
不在我的Windows主目录中。但是我的漫游家庭目录(强制执行网络管理员)。“正确”的答案是“把
.bash_profile
你
的git bash的主目录”,您可以通过要找到
cd ~
那么
pwd
如果找不到~/.bashrc
文件,则可以将所有别名添加到~/.bash_profile
文件中。
例如,要为Git命令(git status
)添加别名,只需添加:
alias gs="git status"
以相同的方式,您可以为Bash命令添加别名(更改目录路径):
alias myd="cd ~/path to my directory"
在您的Git Bash主目录中,应该有一个.gitconfig文件。在此文件中,您可以通过添加添加别名[alias]
。它应该像下面这样:
[alias] st = status co = checkout
简单(如果您拥有.bashrc,则将别名添加到文件末尾):
cat >> ~/.bashrc
粘贴或键入别名列表。按Ctrl+ D,最后运行:
source ~/.bashrc
我的git版本是git version 2.18.0.windows.1我花了一段时间才弄清楚.bashrc在哪里C:\ Program Files \ Git \ etc ---> bash.bashrc希望它能对您有所帮助