我想设置git alias以更改windows中的目录
我有以下git别名设置我想设置git alias以更改windows中的目录,git,Git,我有以下git别名设置 [alias] history = log --all --graph --decorate --oneline project1 = "cd /c/projects/test1" project2 = "cd c:/projects/test2" 但是在运行git项目时,我得到了这个错误 扩展别名“project1”失败;'“cd”不是git命令 我正在Windows 10计算机上尝试此功能,适用于Windows(在7,10上测试),您可以尝
[alias]
history = log --all --graph --decorate --oneline
project1 = "cd /c/projects/test1"
project2 = "cd c:/projects/test2"
但是在运行git项目时,我得到了这个错误
扩展别名“project1”失败;'“cd”不是git命令
我正在Windows 10计算机上尝试此功能,适用于Windows(在7,10上测试),您可以尝试以下功能:
将带有以下内容的macros.doskey
文件放入C:\Users\%userprofile%\bin
mvnx=mvn clean install -s path\to\my\customsettings.xmlfile -T 2C
...
... all your other windows aliases
...
打开cmd
并键入以下信息
reg add "HKCU\Software\Microsoft\Command Processor" /v Autorun /d "doskey /macrofile=\"%userprofile%\bin\macros.doskey\"" /f
reg query "HKCU\Software\Microsoft\Command Processor" /v Autorun
重新启动Windows cmd
之后,在Windows CMD中键入mvnx
,它就会触发上面的别名
非git命令的命令别名应以“!”开头:
[alias]
foo1 = "cd foo1" # will expand to "git cd foo1"
foo2 = "! cd foo2" # will expand to "cd foo2"
@phd是正确的:我只想到了非git命令,但是cd
是特定的,需要修改当前shell的环境
我看不出一种简单的方法可以将cd-foo
转换为别名
您应该了解如何为所使用的shell创建别名或函数。Git别名对于为长Git命令创建别名非常有用,
就像你的历史命令一样。
但是,对于非git命令,我不会使用git别名
出现错误的原因是您的别名被扩展为
git cd /c/projects/test1
git cd c:/projects/test2
但是,cd
不是git命令,您需要的是
cd /c/projects/test1
cd c:/projects/test2
因为这些命令与git无关,所以我会选择另一个工具来实现这一点
从您的屏幕截图来看,您似乎正在使用Powershell。
您可以使用powershell函数来实现以下目标:
function project1 { cd /c/projects/test1 }
function project2 { cd c:/projects/test2 }
将其放入您的powershell profile.ps1文件中,以使这些功能在每次启动powershell时可用。更多信息。为什么要将其设置为Git别名?您可以将其设置为普通别名?”foo2=“!”!cd-foo2“
#将扩展为“cd-foo2”,您确定吗?我认为它扩展到了sh-c“cd foo2”
,这就是为什么这个别名不起作用的原因——它更改了子shell的当前目录,但没有更改当前git
进程的当前目录,更不用说终端中的当前shell了。我认为更改目录的唯一方法是shell别名或函数-只有它们在当前shell的上下文中执行,并且可以更改当前环境。