Last active
April 18, 2024 03:28
-
-
Save InTEGr8or/9fb003d3dfc0c5d7e52bc2e1bd4bf981 to your computer and use it in GitHub Desktop.
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
function Move-GitForward (){ | |
param( | |
[int]$commits | |
) | |
if (-not $commits -or $commits -lt 1) { | |
$commits = 1; | |
} | |
git rev-parse --short HEAD ` | |
| Set-Variable head; | |
git log --pretty=format:'%h' --branches ` | |
| Set-Variable allCommits; | |
$currentIndex = $allCommits.IndexOf($head); | |
if ($currentIndex -lt 1) { | |
throw 'No commits found'; | |
} | |
# TO move towwards the top of the list, subtract from the current index. | |
$targetCommit = $allCommits[$currentIndex - $commits]; | |
git checkout $targetCommit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like to checkout old commits and then move forward.
Standard
git
doesn't handle the move-forward part, so I finally wrote this little diddy.