Skip to content

Instantly share code, notes, and snippets.

@InTEGr8or
Last active April 18, 2024 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InTEGr8or/9fb003d3dfc0c5d7e52bc2e1bd4bf981 to your computer and use it in GitHub Desktop.
Save InTEGr8or/9fb003d3dfc0c5d7e52bc2e1bd4bf981 to your computer and use it in GitHub Desktop.
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
}
@InTEGr8or
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment