Skip to content

Instantly share code, notes, and snippets.

@miyataka
Last active November 27, 2022 11:08
Show Gist options
  • Save miyataka/447f3f1d6be72c68bf3b32f3c95bd46a to your computer and use it in GitHub Desktop.
Save miyataka/447f3f1d6be72c68bf3b32f3c95bd46a to your computer and use it in GitHub Desktop.
git history next / prev command
# cf. https://coderwall.com/p/ok-iyg/git-prev-next
# cf. https://www.yhoka.com/posts/git-next-prev/
[alias]
prev = checkout HEAD^1
next = "!sh -c 'if [ \"$1\" = \"\" ]; then if [ \"$TARGET_BRANCH\" = \"\" ]; then if [ \"$(git branch | grep master)\" = \"\" ]; then TARGET_BRANCH=main; else TARGET_BRANCH=master; fi; fi; else TARGET_BRANCH=$1; fi; git log --reverse --pretty=%H $TARGET_BRANCH | grep $(git rev-parse HEAD) -A 1 | tail -1 | xargs git checkout' -"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment