创建别名 Git Bash Windows 10

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45569288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:21:11  来源:igfitidea点击:

Create alias Git Bash Windows 10

gitbash

提问by Viet

How to create alias for Git Bash on Windows 10? I need to create an alias of the long path to my project folder so I don't have to type it again and again whenever I open bash. I've searched for answers and tried several "correct answers" but none has worked for me so far.

如何在 Windows 10 上为 Git Bash 创建别名?我需要为我的项目文件夹创建一个长路径的别名,这样我就不必在打开 bash 时一次又一次地输入它。我搜索了答案并尝试了几个“正确答案”,但到目前为止没有一个对我有用。

They include: create a .bashrcor some people suggest .bashrc.(after creating this file, I cannot do anything with it. windows says

它们包括:创建一个.bashrc或一些人建议.bashrc.(创建此文件后,我无法对它做任何事情。windows 说

Could not find this item This is no longer located in C:\. Verify the item's location and try again.

找不到该项目 这不再位于 C:\。验证项目的位置,然后重试。

) echo alias='<path>' > .bashrc(iI've also tried >>)

) echo alias='<path>' > .bashrc(我也试过>>)

I can edit the file .bashrcand put aliases in there but none of them works. I've tried editing the .gitconfigfile in my home folder [alias] =''

我可以编辑文件.bashrc并将别名放在那里,但它们都不起作用。我已经尝试编辑.gitconfig我的主文件夹中的文件 [别名] =''

Same result whenever I type: cd <alias name>:

每次输入时结果相同cd <alias name>::

No such file or directory

无此文件或目录

All I need to do is to type: cd and it will lead me to ~///...

我需要做的就是输入:cd 它将引导我到 ~///...

回答by skr

Try this:

尝试这个:

  1. Open the bash terminal
  2. cd ~
  3. vi .bashrc
  4. press ito go edit mode and update it with you alias command.
  5. press Escand press :wq(save and exit)
  6. now close and reopen the bash terminal
  7. check the alias command.
  1. 打开bash终端
  2. 光盘~
  3. vi .bashrc
  4. i进入编辑模式并使用别名命令更新它。
  5. 按下Esc并按下:wq(保存并退出)
  6. 现在关闭并重新打开 bash 终端
  7. 检查别名命令。

if this didn't work create the .bash_profilein the same way and add the line

如果这不起作用.bash_profile,请以相同的方式创建并添加行

if [ -f ~/.bashrc ]; then . ~/.bashrc; fi

回答by Tms91

you can also open and edit the file aliases.sh that you find in the installation path of git

您也可以打开并编辑在git安装路径中找到的文件aliases.sh

C:\path where you installed Git\etc\profile.d\aliases.sh

C:\你安装 Git 的路径\etc\profile.d\aliases.sh

Open it with atom or notepad++ and add a line like

用原子或记事本++打开它并添加一行

alias MyProjectName='C:/<installation_path_of_your project>/'

and save.

并保存。

close and reopen git bash

关闭并重新打开 git bash

now if you write

现在如果你写

MyProjectName

on Bash, it should automatically bring you tothe desired path.

在 Bash 上,它应该会自动将您带到所需的路径。

If it doesn't work try with

如果它不起作用尝试

cd MyProjectName