Last active
May 3, 2023 01:12
-
-
Save ejhayes/854d3b7965f14d41a5387d362c8ed30e to your computer and use it in GitHub Desktop.
Find nearest equivalent git commit that does not differ from the current 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 | |
# Get the HEAD commit hash | |
HEAD=$(git rev-parse HEAD) | |
# Generate a list of all commit hashes in the repository | |
git rev-list --no-merges --all | while read COMMIT; do | |
# Compare the commit to the HEAD | |
if [ -z "$(git diff --name-only $COMMIT $HEAD)" ]; then | |
# If there are no differences, exit the loop and return the commit hash | |
echo "Found commit with no differences: $COMMIT" | |
exit 0 | |
fi | |
done | |
# If no matching commit was found, exit with an error | |
echo "No matching commit found" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment