Created
July 24, 2021 20:16
-
-
Save skylarbpayne/cb809d7b4ccef88b1dc86f6e757445d3 to your computer and use it in GitHub Desktop.
A git alias for smart reversions
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
# 'Smart Revert' | |
# Uses git reset to perform a revert such that: | |
# - Git history stays intact | |
# - Works across merge commits | |
# See this stack overflow answer for information on the solution: | |
# https://stackoverflow.com/a/1470452 | |
# This takes a single argument: a git commit. Note: this can be either | |
# an exact commit, or some expression such as 'HEAD^' | |
[alias] | |
sr = "!f() { \ | |
COMMIT=$(git log -1 --format='format:%H' $1); \ | |
ORIG_COMMIT=$(git log -1 --format='format:%H'); \ | |
git reset --hard ${COMMIT}; \ | |
git reset --soft ${ORIG_COMMIT}; \ | |
git add .; \ | |
git commit -am 'Reverting changes between '${ORIG_COMMIT}' and '${COMMIT}''; \ | |
}; f" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment