Direct naar hoofdinhoud

Git

Onofficiรซle Beta-vertaling

Deze pagina is vertaald door PageTurner AI (beta). Niet officieel goedgekeurd door het project. Een fout gevonden? Probleem melden โ†’

Watโ€‹

Toont git-informatie wanneer je je in een Git-repository bevindt. Werkt ook voor submappen. Voor maximale compatibiliteit zorg ervoor dat je git-executable up-to-date is (bijvoorbeeld wanneer branch- of statusinformatie onjuist is).

Voorbeeldconfiguratieโ€‹

{
"type": "git",
"style": "powerline",
"powerline_symbol": "๎‚ฐ",
"foreground": "#193549",
"background": "#ffeb3b",
"background_templates": [
"{{ if or (.Working.Changed) (.Staging.Changed) }}#FFEB3B{{ end }}",
"{{ if and (gt .Ahead 0) (gt .Behind 0) }}#FFCC80{{ end }}",
"{{ if gt .Ahead 0 }}#B388FF{{ end }}",
"{{ if gt .Behind 0 }}#B388FB{{ end }}"
],
"template": "{{ .UpstreamIcon }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} ๏„ {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} ๏† {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} ๏ƒ‡ {{ .StashCount }}{{ end }}",
"options": {
"fetch_status": true,
"fetch_upstream_icon": true,
"untracked_modes": {
"/Users/user/Projects/oh-my-posh/": "no"
},
"source": "cli",
"mapped_branches": {
"feat/*": "๐Ÿš€ ",
"bug/*": "๐Ÿ› "
}
}
}

Optiesโ€‹

Informatie ophalenโ€‹

Omdat meerdere git-opdrachten de promptervaring kunnen vertragen, halen we standaard geen informatie op. Je kunt de volgende opties op true zetten om het ophalen van aanvullende informatie in te schakelen (en de template te vullen).

NameTypeDefaultDescription
fetch_statusbooleanfalsefetch the local changes
fetch_push_statusbooleanfalsefetch the push-remote ahead/behind information. Requires fetch_status to be enabled
ignore_status[]stringdo not fetch status for these repo's. Uses the repo's root folder and same logic as the exclude_folders property
fetch_upstream_iconbooleanfalsefetch upstream icon
fetch_bare_infobooleanfalsefetch bare repo info
fetch_userUserfalsefetch the current configured user for the repository
untracked_modesmap[string]stringmap of repo's where to override the default untracked files mode:
  • no
  • normal
  • all
For example "untracked_modes": { "/Users/me/repos/repo1": "no" } - defaults to normal for all repo's. If you want to override for all repo's, use * to set the mode instead of the repo path
ignore_submodulesmap[string]stringmap of repo's where to change the --ignore-submodules flag (none, untracked, dirty or all). For example "ignore_submodules": { "/Users/me/repos/repo1": "all" }. If you want to override for all repo's, use * to set the mode instead of the repo path
native_fallbackbooleanfalsewhen set to true and git.exe is not available when inside a WSL2 shared Windows drive, we will fallback to the native git executable to fetch data. Not all information can be displayed in this case
status_formatsmap[string]stringa key, value map allowing to override how individual status items are displayed. For example, "status_formats": { "Added": "Added: %d" } will display the added count as Added: 1 instead of +1. See the Status section for available overrides.
sourcestringcli
  • cli: fetch the information using the git CLI
  • pwsh: fetch the information from the posh-git PowerShell Module
mapped_branchesobjectcustom glyph/text for specific branches. You can use * at the end as a wildcard character for matching
branch_templatestringa template to format that branch name. You can use {{ .Branch }} as reference to the original branch name
disable_with_jjbooleanfalsedisable the git segment in case of a Jujutsu collocated repository

Pictogrammenโ€‹

Branchโ€‹

NameTypeDefaultDescription
branch_iconstring\uE0A0the icon to use in front of the git branch name
branch_identical_iconstring\u2261the icon to display when remote and local are identical
branch_ahead_iconstring\u2191the icon to display when the local branch is ahead of its remote
branch_behind_iconstring\u2193the icon to display when the local branch is behind its remote
branch_gone_iconstring\u2262the icon to display when there's no remote branch
NameTypeDefaultDescription
commit_iconstring\uF417icon/text to display before the commit context (detached HEAD)
tag_iconstring\uF412icon/text to display before the tag context
rebase_iconstring\uE728icon/text to display before the context when in a rebase
cherry_pick_iconstring\uE29Bicon/text to display before the context when doing a cherry-pick
revert_iconstring\uF0E2icon/text to display before the context when doing a revert
merge_iconstring\uE727icon/text to display before the merge context
no_commits_iconstring\uF594icon/text to display when there are no commits in the repo

Upstreamโ€‹

NameTypeDefaultDescription
github_iconstring\uF408icon/text to display when the upstream is GitHub
gitlab_iconstring\uF296icon/text to display when the upstream is GitLab
bitbucket_iconstring\uF171icon/text to display when the upstream is Bitbucket
azure_devops_iconstring\uEBE8icon/text to display when the upstream is Azure DevOps
codecommit_iconstring\uF270icon/text to display when the upstream is AWS CodeCommit
codeberg_iconstring\uF330icon/text to display when the upstream is Codeberg
git_iconstring\uE5FBicon/text to display when the upstream is not known/mapped
upstream_iconsmap[string]stringa key, value map representing the remote URL (or a part of that URL) and icon to use in case the upstream URL contains the key. These get precedence over the standard icons

Template (informatie)โ€‹

standaard template
{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uF044 {{ .Working.String }}{{ end }}{{ if and (.Staging.Changed) (.Working.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uF046 {{ .Staging.String }}{{ end }}

Eigenschappenโ€‹

NameTypeDescription
.RepoNamestringthe repo folder name
.WorkingStatuschanges in the worktree (see below)
.StagingStatusstaged changes in the work tree (see below)
.HEADstringthe current HEAD context (branch/rebase/merge/...)
.Refstringthe current HEAD reference (branch/tag/...)
.Behindintcommits behind of upstream
.Aheadintcommits ahead of upstream
.PushBehindintcommits behind of push remote
.PushAheadintcommits ahead of push remote
.BranchStatusstringthe current branch context (ahead/behind string representation)
.Upstreamstringthe upstream name (remote)
.UpstreamGonebooleanwhether the upstream is gone (no remote)
.UpstreamIconstringthe upstream icon (based on the icons above)
.UpstreamURLstringthe upstream URL for use in hyperlinks in templates: {{ url .UpstreamIcon .UpstreamURL }}
.RawUpstreamURLstringthe raw upstream URL (not cleaned up for display)
.Hashstringthe full commit hash
.ShortHashstringthe short commit hash (7 characters)
.StashCountintthe stash count
.WorktreeCountintthe worktree count
.IsWorkTreebooleanif in a worktree repo or not
.IsBarebooleanif in a bare repo or not, only set when fetch_bare_info is set to true
.Dirstringthe repository's root directory
.RelativeDirstringthe current directory relative to the root directory
.Krakenstringa link to the current HEAD in GitKraken for use in hyperlinks in templates {{ url .HEAD .Kraken }}
.CommitCommitHEAD commit information (see below)
.Detachedbooleantrue when the head is detached
.Mergebooleantrue when in a merge
.RebaseRebasecontains the relevant information when in a rebase
.CherryPickbooleantrue when in a cherry pick
.Revertbooleantrue when in a revert
.UserUserthe current configured user (requires fetch_user to be enabled)
.Remotesmap[string]stringa map of remote names to their URLs
.LatestTagstringthe latest tag name

Statusโ€‹

NameTypeDescription
.Unmergedintnumber of unmerged changes
.Deletedintnumber of deleted changes
.Addedintnumber of added changes
.Modifiedintnumber of modified changes
.Untrackedintnumber of untracked changes
.Changedbooleanif the status contains changes or not
.Stringstringa string representation of the changes above

Lokale wijzigingen gebruiken de volgende syntax:

IconDescription
xUnmerged
-Deleted
+Added
~Modified
?Untracked

Commitโ€‹

NameTypeDescription
.AuthorUserthe author of the commit (see below)
.CommitterUserthe committer of the commit (see below)
.Subjectstringthe commit subject
.Timestamptime.Timethe commit timestamp
.Shastringthe commit SHA1
.RefsRefsthe commit references
Gebruikerโ€‹
NameTypeDescription
.Namestringthe user's name
.Emailstringthe user's email
Refsโ€‹
NameTypeDescription
.Heads[]stringbranches
.Tags[]stringcommit's tags
.Remotes[]stringremote references

Aangezien dit arrays van strings zijn, kun je ze samenvoegen met de join functie:

{{ join ", " .Commit.Refs.Tags }}

Rebaseโ€‹

NameTypeDescription
.Currentintthe current rebase step
.Totalintthe total number of rebase steps
.HEADstringthe current HEAD
.Ontostringthe branch we're rebasing onto

posh-gitโ€‹

Als je de standaard posh-git-output wilt tonen, gebruik niet dit segment maar voeg het volgende fragment toe na het initialiseren van Oh My Posh in je $PROFILE:

function Set-PoshGitStatus {
$global:GitStatus = Get-GitStatus
$env:POSH_GIT_STRING = Write-GitStatus -Status $global:GitStatus
}
New-Alias -Name 'Set-PoshContext' -Value 'Set-PoshGitStatus' -Scope Global -Force

Je kunt dan de POSH_GIT_STRING omgevingsvariabele gebruiken in een tekstsegment:

{
"template": "{{ if .Env.POSH_GIT_STRING }} {{ .Env.POSH_GIT_STRING }} {{ end }}"
}