Created
May 1, 2014 15:27
-
-
Save sheepmaster/d696bef676e72c493988 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python | |
| """Prints the last checked out branches (i.e. HEAD, @{-1}, @{-2}, ...), one per line. | |
| Duplicates will be skipped, so the line number does not necessarily correspond to the |n| in `@{-n}`. | |
| """ | |
| import re | |
| import subprocess | |
| lines = subprocess.check_output(['git', 'reflog']).splitlines() | |
| branches = set() | |
| for line in lines: | |
| match = re.match(r'^[0-9a-f]+ HEAD@\{\d+\}: ' | |
| r'checkout: moving from \S+ to (\S+)$', line) | |
| if match: | |
| branch = match.groups()[0] | |
| if branch == 'HEAD': | |
| continue | |
| if not branch in branches: | |
| branches.add(branch) | |
| print branch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment