function gn{git init}
# @args you can pass multi arguments for example
# ga fileName1 fileName2
function add{git add @args}
function commit { git commit -m @args }
function gac{git add .;git commit -m @args}
function gpm{git push origin master}
function pull{git pull origin master}
function gl{git log}
function glo{git log --oneline}
function gch{git checkout @args}
# @args is optional to add argument
function gb{git branch @args}
function gs{git status}
function gd{git diff}
保存它并关闭PowerShell,再次打开它并通过函数名调用别名命令,例如初始化git仓库写入此命令: gn 要添加文件,请编写以下命令 add fileName1 请参阅GIF图像
function gs{git status}
function ga{git add .}
function gfa{git fetch --all}
function grman{git rebase -i main}
function grmas{git rebase -i master}
function grdev{git rebase -i develop}
function gitc{ git commit -m @args }
function gac{git add .;git commit -m @args}
function pushmas{git push origin master}
function pushman{git push origin main}
function pushdev{git push origin develop}
function pullman{git pull origin main}
function pullmas{git pull origin main}
function pulldev{git pull origin develop}
function pull{git pull origin master}
function gl{git log}
function glo{git log --oneline}
function gch{git checkout @args}
function gcn{git checkout -b @args}
function gman{git checkout main}
function gmas{git checkout master}
function gdev{git checkout develop}
function gb{git branch @args}
function gs{git status}
function gd{git diff}
8条答案
按热度按时间zed5wv101#
你必须先创建一个函数,其中包含你的命令。然后创建该函数的别名。
你可能也会对名为posh-git的操作系统项目感兴趣,该项目旨在为git命令提供一个powershell环境,用PS类型的函数 Package git命令,并提供一个新的提示符,在提示符中显示状态和分支。
编辑:忘记添加如何找到如何使用Powershell做到这一点。
这将向您展示如何使用set-alias为带有参数、管道等的命令创建别名的示例(最后一个示例适用于此处)。
o75abkj42#
我刚刚为自己创建了一些快捷方式,并希望与大家分享:
创建PowerShell配置文件(如果您还没有):
打开它进行编辑:
添加以下函数和别名:
当您重新启动PowerShell会话时,您还应该能够将参数传递给别名。例如:
更新:
下面是我常用的一些快捷方式:
myzjeezk3#
我不知道PowerShell,但你可以setup aliases directly in Git。
jm2pwxwz4#
我创建了posh-git-alias,您可以将其添加到PowerShell
$PROFILE
中。nzrxty8p5#
您需要创建一个profile.ps1文件,将其放在我的文档中名为WindowsPowerShell的文件夹中
然后在profile.ps1中放入如下行:
2cmtqfgy6#
您可以创建在打开PowerShell时自动运行的PowerShell配置文件首先打开PowerShell并创建PowerShell配置文件(如果您还没有配置文件):
New-Item -Type file -Path $PROFILE -Force
此命令将在Documents中创建目录调用**
WindowsPowerShell
在此目录内将创建文件调用Microsoft.PowerShell_profile.ps1
**如果要了解**
Microsoft.PowerShell_profile.ps1
**的完整路径,请编写以下命令:$PROFILE
使用以下命令从PowerShell打开它
powershell_ise.exe $PROFILE
并编写所有要为其指定别名的命令,例如:
保存它并关闭PowerShell,再次打开它并通过函数名调用别名命令,例如初始化git仓库写入此命令:
gn
要添加文件,请编写以下命令
add fileName1
请参阅GIF图像
要显示别名命令的内容,请编写以下命令:
Get-Content $PROFILE
mhd8tkvw7#
如果使用PowerShell,则需要添加函数,包括要为其创建别名的命令。
例如,要为
git fetch -all
创建别名,则需要在文件Microsoft.PowerShell_profile
中添加以下内容:然后,如果您在PowerShell或WindowsTerminal中运行
gfa
,则会执行git fetch --all
。注意:要在记事本中打开
Microsoft.PowerShell_profile
文件,请在PowerShell或WindowsTerminal中运行notepad $profile
.或者导航到C:\Users\YOUR_USER\Documents\WindowsPowerShell
以获取该文件.以下是常用函数的列表:
这个是这个。
mspsb9vt8#
在Windows上,我使用了位于用户个人文件夹中的
.gitconfig
文件中的以下内容: