reflog¶
For git-reflog(1).
Overview¶
Manage git reflog using GitReflogManager (collection-level)
and GitReflogEntryCmd (per-entry operations).
Example¶
from libvcs.cmd.git import Git
git = Git(path='/path/to/repo')
# List reflog entries
entries = git.reflog.ls()
# List entries for a specific ref
head_entries = git.reflog.ls(ref='HEAD')
# Check if reflog exists for a ref
git.reflog.exists(ref='main')
# Expire old reflog entries
git.reflog.expire(ref='HEAD', expire='90.days.ago')
API Reference¶
Bases:
objectTraverse and manage git reflog entries with ORM-like filtering via QueryList.
Wrap some of git-reflog(1), manager.
Examples
>>> GitReflogManager(path=tmp_path) <GitReflogManager path=...>
>>> GitReflogManager(path=tmp_path).run('show') 'fatal: not a git repository (or any of the parent directories): .git'
>>> len(GitReflogManager(path=example_git_repo.path).run('show')) > 0 True
Run a command against a git repository’s reflog.
Wraps git reflog.
Examples
>>> len(GitReflogManager(path=example_git_repo.path).run('show')) > 0 True
Show reflog for a ref.
Examples
>>> result = GitReflogManager(path=example_git_repo.path).show() >>> len(result) > 0 True
>>> result = GitReflogManager(path=example_git_repo.path).show(number=5) >>> len(result) > 0 True
Expire old reflog entries.
- Parameters:
expire (str | None) – Expire entries older than this time.
expire_unreachable (str | None) – Expire unreachable entries older than this time.
rewrite (bool) – Adjust reflog entries as old entries are pruned.
updateref (bool) – Update ref to pruned value.
stale_fix (bool) – Prune stale git-hierarchies too.
dry_run (bool) – Don’t actually prune, just report.
verbose (bool) – Print extra information.
all_refs (bool) – Process reflogs of all refs.
single_worktree (bool) – Only process reflogs for current worktree.
log_in_real_time (bool)
- Return type:
Examples
>>> result = GitReflogManager(path=example_git_repo.path).expire( ... dry_run=True ... ) >>> 'error' in result.lower() or result == '' True
Check if a reflog exists for a ref.
Examples
>>> GitReflogManager(path=example_git_repo.path).exists('HEAD') True
>>> GitReflogManager(path=example_git_repo.path).exists( ... 'refs/heads/nonexistent-branch-xyz123456' ... ) False
Parse reflog output into structured data.
Examples
>>> entries = GitReflogManager(path=example_git_repo.path)._ls() >>> len(entries) > 0 True
List reflog entries as GitReflogEntry objects.
- Parameters:
- Returns:
List of reflog entries with ORM-like filtering.
- Return type:
Examples
>>> entries = GitReflogManager(path=example_git_repo.path).ls() >>> isinstance(entries, QueryList) True >>> len(entries) > 0 True
Get a specific reflog entry.
- Parameters:
- Returns:
The matching reflog entry.
- Return type:
- Raises:
ObjectDoesNotExist – If no matching entry found.
MultipleObjectsReturned – If multiple entries match.
Examples
>>> entry = GitReflogManager(path=example_git_repo.path).get( ... refspec='HEAD@{0}' ... ) >>> entry.refspec 'HEAD@{0}'
Filter reflog entries.
- Parameters:
- Returns:
Filtered list of reflog entries.
- Return type:
Examples
>>> entries = GitReflogManager(path=example_git_repo.path).filter( ... action='commit' ... ) >>> isinstance(entries, QueryList) True
Bases:
objectRun git commands targeting a specific reflog entry.
Wrap some of git-reflog(1) for specific entry operations.
Examples
>>> GitReflogEntryCmd( ... path=example_git_repo.path, ... refspec='HEAD@{0}', ... ) <GitReflogEntryCmd HEAD@{0}>
Run a command against a specific reflog entry.
Wraps git reflog.
Examples
>>> GitReflogEntryCmd( ... path=example_git_repo.path, ... refspec='HEAD@{0}', ... ).run('show') '...'
Show this reflog entry.
Examples
>>> result = GitReflogEntryCmd( ... path=example_git_repo.path, ... refspec='HEAD@{0}', ... ).show() >>> len(result) > 0 True
Delete this reflog entry.
Examples
>>> result = GitReflogEntryCmd( ... path=example_git_repo.path, ... refspec='HEAD@{0}', ... ).delete(dry_run=True) >>> 'error' in result.lower() or result == '' True