Skip to content

Get‑GitBranchCommit

viscalyxbot edited this page Sep 30, 2025 · 1 revision

SYNOPSIS

Retrieves the commit ID(s) for a specified Git branch.

SYNTAX

NoParameter (Default)

Get-GitBranchCommit [-BranchName <String>] [<CommonParameters>]

First

Get-GitBranchCommit [-BranchName <String>] [-First <UInt32>] 
 [<CommonParameters>]

Last

Get-GitBranchCommit [-BranchName <String>] [-Last <UInt32>] 
 [<CommonParameters>]

Latest

Get-GitBranchCommit [-BranchName <String>] [-Latest] [<CommonParameters>]

Range

Get-GitBranchCommit -From <String> -To <String> [<CommonParameters>]

DESCRIPTION

The Get-GitBranchCommit command retrieves the commit ID(s) for a specified Git branch. It provides options to retrieve the latest commit ID, a specific number of latest commit IDs, or the first X number of commit IDs.

EXAMPLES

EXAMPLE 1

Get-GitBranchCommit -BranchName 'feature/branch'

Retrieves all commit IDs for the 'feature/branch' Git branch.

EXAMPLE 2

Get-GitBranchCommit -Latest

Retrieves only the latest commit ID for the current Git branch.

EXAMPLE 3

Get-GitBranchCommit -Last 5

Retrieves the 5 latest commit IDs for the current Git branch.

EXAMPLE 4

Get-GitBranchCommit -First 3

Retrieves the first 3 commit IDs for the current Git branch.

EXAMPLE 5

Get-GitBranchCommit -From 'main' -To 'HEAD'

Retrieves all commit IDs between the main branch and HEAD.

EXAMPLE 6

Get-GitBranchCommit -From 'v1.0.0' -To 'v2.0.0'

Retrieves all commit IDs between version tags v1.0.0 and v2.0.0.

EXAMPLE 7

Get-GitBranchCommit -From 'abc123' -To 'def456'

Retrieves all commit IDs between two specific commit hashes.

PARAMETERS

-BranchName

Specifies the name of the Git branch. If not provided, the current branch will be used.

Type: String
Parameter Sets: NoParameter, First, Last, Latest
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-From

Specifies the starting reference (commit, branch, tag, or HEAD) for the range. Used with the To parameter to get commits between two references.

Type: String
Parameter Sets: Range
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Last

Retrieves the specified number of latest commit IDs. The order will be from the newest to the oldest commit.

Type: UInt32
Parameter Sets: Last
Aliases:

Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False

-Latest

Retrieves only the latest commit ID.

Type: SwitchParameter
Parameter Sets: Latest
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-To

Specifies the ending reference (commit, branch, tag, or HEAD) for the range. Used with the From parameter to get commits between two references.

Type: String
Parameter Sets: Range
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-First

Retrieves the first X number of commit IDs. The order will be from the oldest to the newest commit.

Type: UInt32
Parameter Sets: First
Aliases:

Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

None

This function does not accept pipeline input.

OUTPUTS

System.String

The commit ID(s) for the specified Git branch.

NOTES

RELATED LINKS

Clone this wiki locally