如何在从git-scm.com下载的Git Bash for Windows中使用别名命令?
我的意思是Bash命令不是Git。
(Windows 7的)
编辑:
在.bashrc
文件中编写别名(由@gturri建议)不在控制台中添加它(在系统重启后)(我从未为ls
命令编写别名,因此它应该是一些默认别名。)
要配置bash别名,它就像你在Unix平台上一样:把它们放在家里的.bashrc
中:
cd
echo alias ll=\'ls -l\' >> .bashrc
要将此更改考虑在内,您应该获取此文件(即:运行source .bashrc
)或重新启动终端
(在某些情况下*你可以在.bashrc
中找到C:\Users\<username>\AppData\Local\GitHub\PortableGit_\etc\profile.d\aliases.sh.
文件的等效文件而你应该在aliases.sh.
中添加别名)
(*这种情况是从包含GitBash的https://git-scm.com/download/win安装Git for Windows GUI版本时)
我遇到了同样的问题,我无法弄清楚如何在Windows上找到Git Bash使用的别名。搜索了一段时间后,我在C:\Program Files\Git\etc\profile.d\aliases.sh
下找到了aliases.sh文件。
这是Windows 7下的路径,也许在其他安装中可能不同。
只需在管理员模式下使用首选编辑器打开它。保存后,重新加载命令提示符。
我希望这可以帮助你!
请遵循以下步骤:
.bashrc
的文件C:\Users\USERNAME\.bashrc
如果文件.bashrc
不存在,则使用以下步骤创建它:
打开命令提示符并转到C:\Users\USERNAME\
。
输入命令notepad ~/.bashrc
它生成.bashrc
文件。# ----------------------
# Git Command Aliases
# ----------------------
alias ga='git add'
alias gaa='git add .'
alias gaaa='git add --all'
# ----------------------
# WP CLI
# ----------------------
alias wpthl='wp theme list'
alias wppll='wp plugin list'
现在您可以使用命令:
ga
而不是git add .
wpthl
而不是wp theme list
例如。我使用wpthl
作为WP CLI命令wp theme list
。
Yum@M MINGW64 /c/xampp/htdocs/dev.test
$ wpthl
+------------------------+----------+-----------+----------+
| name | status | update | version |
+------------------------+----------+-----------+----------+
| twentyeleven | inactive | none | 2.8 |
| twentyfifteen | inactive | none | 2.0 |
| twentyfourteen | inactive | none | 2.2 |
| twentyseventeen | inactive | available | 1.6 |
| twentysixteen | inactive | none | 1.5 |
| twentyten | inactive | none | 2.5 |
| twentythirteen | inactive | none | 2.4 |
| twentytwelve | inactive | none | 2.5 |
有关更多详细信息,请阅读文章Keyboard shortcut/aliases for the WP CLI, Git, Grunt & PHPCS commands for windows
C:\Users\ [youruserdirectory] \bash_profile
输入桌面,查看您是否在上面的“目录位置”区域中找到了桌面位置或所需位置
注意:[桌面]可以是您选择的名称,并且可以在CMD窗口中输入时到达您想要到达的位置。
设置别名有两种简单的方法。
使用Bash
打开bash终端并输入git命令。例如:
$ git config --global alias.a add
$ git config --global alias.aa 'add .'
$ git config --global alias.cm 'commit -m'
$ git config --global alias.s status
---
---
它最终会在.gitconfig文件中添加这些别名。
更新.gitconfig文件
在Windows环境中打开位于“C:\ Users \ username \ .gitconfig”的.gitconfig文件。然后添加以下行:
[alias]
a = add
aa = add .
cm = commit -m
gau = add --update
au = add --update
b = branch
---
---