如何别名命令在Git Bash为Windows下载从Git -scm.com ?

我指的是Bash命令而不是Git。

(windows7多)


编辑:

在.bashrc文件中编写别名(根据@gturri的建议),而不是将其添加到控制台。(在系统重新启动后)(我从未为ls命令写过别名,所以它应该是一些默认的别名。)


当前回答

要配置bash别名,就像你在Unix平台上一样:把它们放在你家里的.bashrc文件中:

cd
echo alias ll=\'ls -l\' >> .bashrc

要考虑到这个变化,你应该源这个文件(即:run source .bashrc)或重新启动你的终端

(在某些情况下*你可以在C:\Users\<username>\AppData\Local\GitHub\PortableGit_\etc\profile.d\alias .sh中找到等价的.bashrc文件。并且您应该在alias .sh中添加别名。)

(*这种情况是当你从https://git-scm.com/download/win安装Git for Windows GUI发布时,包含GitBash)

其他回答

您可以在.gitconfig文件中手动添加它

[alias]
    cm = "commit -m"

或者使用脚本:

git config --global alias.cm "commit -m"

下面是.gitconfig的截图

打开:C:\Users\ [youruserdirectory] \bash_profile 在您的bash_profile文件类型- alias desk='cd "[目录位置]"' 刷新bash_profile文件所在的User目录,然后重新打开CMD或Git Bash窗口

输入“desk”,看看你是否在上面的“DIRECTORY location”区域中找到了桌面位置或你想要的位置

注意:[desk]可以是你选择的任何名称,当在CMD窗口中输入时,应该让你到达你想要到达的位置。

添加临时别名:

Goto终端(我使用git bash for windows)。 输入$ alias gpuom='git push origin master' 要查看所有别名的列表键入$ alias按Enter。

添加永久别名:

Goto终端(我使用git bash for windows)。 输入$ vim ~/。bashrc并按Enter(我猜你熟悉vim)。 添加您的新别名(参考下面的代码片段)。 #我的自定义别名 别名gpuom='git push origin master' 别名gplom='git pull origin master' 保存并退出(按Esc键,然后输入:wq)。 要查看所有别名的列表键入$ alias按Enter。

有两种简单的方法来设置别名。

使用Bash 正在更新.gitconfig文件

使用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文件

打开位于'C:\Users\username\. gitconfig文件。Windows环境下的gitconfig。然后添加以下几行:

[alias]  
a = add  
aa = add . 
cm = commit -m 
gau = add --update 
au = add --update
b = branch
---
---

遵循以下步骤:

打开位置C:\Users\USERNAME\.bashrc的文件 如果.bashrc文件不存在,那么使用以下步骤创建它: 打开命令提示符,进入c:\ users \ username \。 输入命令notepad ~/.bashrc 它生成.bashrc文件。 添加以下示例命令的WP CLI, Git, Grunt和PHPCS等。


# ----------------------
# 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添加。 WPTHL代替wp主题列表

如。我已经使用wpthl作为WP CLI命令的WP主题列表。

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      |

有关更多详细信息,请阅读文章WP CLI, Git, Grunt和PHPCS命令的键盘快捷键/别名