Last active
November 13, 2020 16:27
-
-
Save brianvanderlugt/feec88b9d391b4e869ff36d8e8889054 to your computer and use it in GitHub Desktop.
GitRebaseBranches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(Mandatory)] | |
[String[]]$Branches | |
) | |
$newLineChar = [Environment]::NewLine | |
Write-Output $newLineChar | |
[String[]]$commitCountMsgs = @() | |
[String[]]$scriptOutputLines = @() | |
for ($i=0;$i -lt ($Branches.Count - 1); $i++){ | |
$baseBranch = $Branches[$i] | |
$rebaseBranch = $Branches[$i + 1] | |
$mergeBaseCmd = "git merge-base $baseBranch $rebaseBranch" | |
$mergeBase = Invoke-Expression -Command $mergeBaseCmd | |
$branchLastRefCmd = "git rev-parse $rebaseBranch" | |
$branchLastRef = Invoke-Expression -Command $branchLastRefCmd | |
$commitCountCmd = "git rev-list ${mergeBase}..${branchLastRef} --count" | |
$commitCount = Invoke-Expression -Command $commitCountCmd | |
$commitCountMsgs += "$commitCount commits between $baseBranch & $rebaseBranch." | |
$scriptOutputLines += "git checkout $rebaseBranch" | |
$scriptOutputLines += "git rebase --onto $baseBranch ${rebaseBranch}~${commitCount} $rebaseBranch" | |
} | |
Write-Output $commitCountMsgs | |
Write-Output $newLineChar | |
Write-Output $scriptOutputLines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment