Treat git log as a book, exec git next
or git prev
to checkout the next or the previous commit.
-
-
Save fannheyward/aa1a861cabeec4b46f33311b62accb57 to your computer and use it in GitHub Desktop.
Git checkout next / prev commit
This file contains 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
#!/bin/sh | |
first() { | |
branch=refs/heads/master | |
git log --reverse --pretty=%H $branch | head -1 | xargs git checkout | |
} | |
first "$@" |
This file contains 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
#!/bin/sh | |
last() { | |
branch=refs/heads/master | |
git log --pretty=%H $branch | head -1 | xargs git checkout | |
} | |
last "$@" |
This file contains 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
#!/bin/sh | |
next() { | |
branch=refs/heads/master | |
if [ -z "$1" ]; then | |
n=1 | |
else | |
n=$1 | |
fi | |
git log --reverse --pretty=%H $branch | grep -A $n $(git rev-parse HEAD) | tail -1 | xargs git checkout | |
} | |
next "$@" |
This file contains 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
#!/bin/sh | |
prev() { | |
branch=refs/heads/master | |
if [ -z "$1" ]; then | |
n=1 | |
else | |
n=$1 | |
fi | |
git checkout HEAD~$n | |
} | |
prev "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment