Last active
February 27, 2026 00:30
-
-
Save tigerhawkvok/0123f344a976447db1f3bfd342a134ca to your computer and use it in GitHub Desktop.
Find dangling commits
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
| #!python3 | |
| import json | |
| import subprocess | |
| from pathlib import Path | |
| filterPhrases = [] | |
| danglingSTDOut = subprocess.run(["git", "fsck", "--lost-found"], stdout= subprocess.PIPE, stderr= subprocess.PIPE).stdout.decode("utf-8") | |
| dangling = [x.split(" ").pop() for x in danglingSTDOut.splitlines() if "commit" in x] | |
| details = [subprocess.run(["git", "show", "-s", "--format=reference", x], stdout= subprocess.PIPE, stderr= subprocess.PIPE).stdout.decode("utf-8") for x in dangling] | |
| filtered = [x.strip() for x in details if any([len(filterPhrases) == 0, *[_phrase not in x for _phrase in filterPhrases]])] | |
| sortCommits = sorted(filtered, key=lambda x: x.rsplit(", ", 1)[-1], reverse= True) | |
| Path("dangling.json").write_text(json.dumps(sortCommits, indent= 4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment