git 명령에 대한 PowerShell의 별칭을 생성하시겠습니까?
PowerShell에서 cmdlet용 별칭을 생성하는 방법은 이해하지만 PowerShell에서 다음과 같은 별칭을 생성하고 싶습니다.git status
정당하게gs
,그리고.git pull origin master
~하듯이gpm
누가 나에게 올바른 방향을 가르쳐 줄 수 있습니까?
먼저 명령이 포함된 함수를 만들어야 합니다.그런 다음 해당 함수에 대한 별칭을 만듭니다.
PS C:\Users\jpogran\code\git\scripts> function get-gitstatus { git status }
PS C:\Users\jpogran\code\git\scripts> get-gitstatus
# On branch master
nothing to commit (working directory clean)
PS C:\Users\jpogran\code\git\scripts> Set-Alias -Name gs -Value get-gitstatus
PS C:\Users\jpogran\code\git\scripts> gs
# On branch master
nothing to commit (working directory clean)
또한 git 명령을 위한 파워셸 환경을 제공하는 것을 목표로 하는 posh-git라는 OS 프로젝트에 관심이 있을 수 있습니다.PS 유형 함수로 git 명령을 래핑하고 프롬프트의 상태와 분기를 표시하는 새로운 프롬프트를 제공합니다.
편집: Powershell을 사용하여 이 작업을 수행하는 방법을 추가하는 것을 잊었습니다.
PS C:\Users\jpogran\code\git\scripts> get-help set-alias -examples
여기에서는 set-alias를 사용하여 매개 변수, 파이프라인 등을 사용하여 명령에 대한 별칭을 만드는 방법의 예를 보여 줍니다.
몇 가지 바로 가기를 만들고 공유하려고 합니다.
PowerShell 프로필 생성(아직 프로필이 없는 경우):
New-Item -Type file -Path $PROFILE -Force
편집할 파일 열기:
notepad $PROFILE
다음 함수 및 별칭을 추가합니다.
function Get-GitStatus { & git status $args }
New-Alias -Name s -Value Get-GitStatus
function Set-GitCommit { & git commit -am $args }
New-Alias -Name c -Value Set-GitCommit
PowerShell 세션을 다시 시작할 때 별칭에도 인수를 전달할 수 있어야 합니다. 예:
c "This is a commit message"
업데이트:
다음은 자주 사용하는 바로 가기입니다.
function Get-GitStatus { & git status -sb $args }
New-Alias -Name s -Value Get-GitStatus -Force -Option AllScope
function Get-GitCommit { & git commit -ev $args }
New-Alias -Name c -Value Get-GitCommit -Force -Option AllScope
function Get-GitAdd { & git add --all $args }
New-Alias -Name ga -Value Get-GitAdd -Force -Option AllScope
function Get-GitTree { & git log --graph --oneline --decorate $args }
New-Alias -Name t -Value Get-GitTree -Force -Option AllScope
function Get-GitPush { & git push $args }
New-Alias -Name gps -Value Get-GitPush -Force -Option AllScope
function Get-GitPull { & git pull $args }
New-Alias -Name gpl -Value Get-GitPull -Force -Option AllScope
function Get-GitFetch { & git fetch $args }
New-Alias -Name f -Value Get-GitFetch -Force -Option AllScope
function Get-GitCheckout { & git checkout $args }
New-Alias -Name co -Value Get-GitCheckout -Force -Option AllScope
function Get-GitBranch { & git branch $args }
New-Alias -Name b -Value Get-GitBranch -Force -Option AllScope
function Get-GitRemote { & git remote -v $args }
New-Alias -Name r -Value Get-GitRemote -Force -Option AllScope
PowerShell에 추가할 수 있는 posh-git-alias를 만들었습니다.$PROFILE
.
PowerShell은 모르지만 Git에서 직접 별칭을 설정할 수 있습니다.
내 문서에서 Windows PowerShell이라는 폴더에 profile.ps1 파일을 만들어야 합니다.
그런 다음 profile.ps1에 다음과 같은 줄을 입력합니다.
set-alias wit 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\witadmin.exe'
PowerShell을 열면 자동으로 실행되는 PowerShell 프로파일을 생성할 수 있습니다. 먼저 PowerShell을 열고 PowerShell 프로파일을 생성할 수 있습니다(아직 없는 경우).
New-Item -Type file -Path $PROFILE -Force
이 명령은 이 디렉토리 내의 문서 호출에 디렉토리를 작성합니다. 파일 호출을 작성합니다.
이 명령어를 작성하는 전체 경로를 알고 싶다면 다음과 같이 하십시오.
$PROFILE
이 명령을 사용하여 PowerShell에서 열기
powershell_ise.exe $PROFILE
그리고 다음과 같이 별칭을 지정할 모든 명령을 작성합니다.
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을 닫고 다시 열고 함수 이름으로 alias 명령을 호출합니다(예: git 저장소 초기화). 다음 명령을 작성합니다.
gn
파일을 추가하려면 이 명령을 씁니다.
add fileName1
GIF 이미지 참조
별칭 명령의 내용을 표시하려면 다음 명령을 작성합니다.
Get-Content $PROFILE
PowerShell을 사용하는 경우 별칭을 생성할 명령을 포함한 기능을 추가해야 합니다.
" 들어대별생경칭을성우는하려한예를다에음▁for경▁alias우▁an▁for는생,▁yougit fetch -all
.Microsoft.PowerShell_profile
:
function gfa{git fetch --all}
그럼 당신이 도망가면,gfa
PowerShell 또는 Windows에서 사용할 수 있습니다.터미널, 그럼git fetch --all
실행됩니다.
참고: 열기Microsoft.PowerShell_profile
을 넣고 을 실행합니다.notepad $profile
PowerShell 또는 Windows에서 사용할 수 있습니다.터미널.또는 다음으로 이동합니다.C:\Users\YOUR_USER\Documents\WindowsPowerShell
파일을 가져올 수 있습니다.
다음은 일반적인 기능 목록입니다.
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}
이 GitHub Gist는 내 자신의 링크입니다. Microsoft.PowerShell_profile
.
이 질문에는 늦었을 수도 있지만, 여전히 비슷한 질문을 하는 사람은 이 파워셸 모듈을 설치하십시오.
PS> Install-Module -Name git-aliases
설명에 따르면,
Oh My Zsh의 Git 플러그인에서 부분 Git 별칭을 제공하는 PowerShell 모듈입니다.
서는콘 사다니합에서 합니다..gitconfig
사용자 홈 폴더에 있는 파일:
[alias]
co = checkout
ci = commit
st = status
sw = switch
d = diff
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
type = cat-file -t
dump = cat-file -p
언급URL : https://stackoverflow.com/questions/2858484/creating-aliases-in-powershell-for-git-commands
'it-source' 카테고리의 다른 글
도커 합성을 사용하여 컨테이너에 파일 복사 (0) | 2023.07.30 |
---|---|
Spring Hibernate Template 실행 메서드가 Oracle에서 카운트 쿼리에 대해 반환하는 개체 유형은 무엇입니까? (0) | 2023.07.30 |
powershell에서 문자열을 정의하기 위한 단일 따옴표와 이중 따옴표의 차이점은 무엇입니까? (0) | 2023.07.25 |
Spring Security : API용 JWT 토큰 및 웹용 세션 (0) | 2023.07.25 |
현재 노드 버전 확인 (0) | 2023.07.25 |