2013-06-02 20:08:32 +0000 2013-06-02 20:08:32 +0000
93
93
Advertisement

如何在Windows中修改Git Bash配置文件?

Advertisement

我在Windows 7上使用Git Bash,想设置Bash配置文件的别名,如alias gs='git status',以方便我的生活。怎样才能做到这一点?

Advertisement
Advertisement

答案 (6)

120
120
120
2013-06-02 20:34:21 +0000

当你打开Git Bash时,默认应该在你的主目录下。现在创建.bashrc文件(如果在Windows 7上,该文件应该命名为.bashrc.)。

如果你不在主目录中,通过键入来改变它。cd

cd

然后按Enter键。cd,如果后面没有列出任何其他参数,将始终返回主目录。

您可以通过键入:

touch

创建文件。

touch .bashrc

然后用Vim编辑它,或者你可以尝试用Windows编辑器,但我不推荐,因为有一些文本格式问题。

vim .bashrc

按i键切换到插入模式。

输入别名。

alias gs=‘git status’

按Esc键退出插入模式。

输入以下内容保存并关闭文件:wqEnter。

:wEnter只会保存你的文件。

:q!Enter将退出编辑器而不保存文件。

最后,通过键入更新文件以使用新的更改。

source .bashrc

30
30
30
2013-06-02 20:34:58 +0000

你可以把.bash_profile放在你的用户目录里。C:\Users<username>

你也可以创建一些git-only的别名,这样你就可以只用git st来做git status,在C:\Users<username>.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
0
Advertisement
0
0
2016-07-04 11:27:18 +0000
Advertisement

在 Git Bash 主目录下,应该有一个 .gitconfig 文件。在这个文件中,你可以通过添加[alias]来添加你的别名。它应该像下面这样。

[alias]
st = status
co = checkout
0
0
0
2017-10-28 15:54:10 +0000

简单地(如果你有.bashrc,你会在文件末尾添加别名):

cat >> ~/.bashrc

粘贴或输入别名列表。按Ctrl + D,最后运行。

source ~/.bashrc
0
Advertisement
0
0
2019-10-17 23:27:41 +0000
Advertisement

我的git版本是git 2.18.0.windows.1 我花了点时间才弄清楚.bashrc在哪里 C:\Program Files\Git\etc —> bash.bashrc 希望能帮到你。

0
0
0
2018-01-25 22:02:23 +0000

如果你找不到你的~/.bashrc文件,你可以将所有的别名添加到你的~/.bash_profile文件中。

例如,要为 Git 命令(git status)添加别名,只需添加:

alias gs="git status"

同样,你也可以为 Bash 命令(更改目录路径)添加别名:

alias myd="cd ~/path to my directory"
```。
Advertisement

相关问题

3
19
10
28
9
Advertisement
Advertisement