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¶
- class libvcs.cmd.git.GitReflogManager(*, path, cmd=None)[source]¶
Bases:
objectTraverse and manage git reflog entries with ORM-like filtering via QueryList.
Wrap some of git-reflog(1), manager.
- Parameters:
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
- __init__(*, path, cmd=None)[source]¶
Wrap some of git-reflog(1), manager.
- Parameters:
- Return type:
None
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
-
path:
Path¶ Directory to check out
- run(command=None, local_flags=None, *, log_in_real_time=False, check_returncode=None, **kwargs)[source]¶
Run a command against a git repository’s reflog.
Wraps git reflog.
- Parameters:
- Return type:
Examples
>>> len(GitReflogManager(path=example_git_repo.path).run('show')) > 0 True
- show(ref='HEAD', *, number=None, log_in_real_time=False, check_returncode=None)[source]¶
Show reflog for a ref.
- Parameters:
- Return type:
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(*, expire=None, expire_unreachable=None, rewrite=False, updateref=False, stale_fix=False, dry_run=False, verbose=False, all_refs=False, single_worktree=False, refs=None, log_in_real_time=False, check_returncode=None)[source]¶
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)
check_returncode (bool | None)
- Return type:
Examples
>>> result = GitReflogManager(path=example_git_repo.path).expire( ... dry_run=True ... ) >>> 'error' in result.lower() or result == '' True
- exists(ref, *, log_in_real_time=False, check_returncode=None)[source]¶
Check if a reflog exists for a ref.
- Parameters:
- Returns:
True if reflog exists, False otherwise.
- Return type:
Examples
>>> GitReflogManager(path=example_git_repo.path).exists('HEAD') True
>>> GitReflogManager(path=example_git_repo.path).exists( ... 'refs/heads/nonexistent-branch-xyz123456' ... ) False
- _ls(ref='HEAD', *, number=None, log_in_real_time=False, check_returncode=None)[source]¶
Parse reflog output into structured data.
- Parameters:
- Returns:
List of parsed reflog entries.
- Return type:
Examples
>>> entries = GitReflogManager(path=example_git_repo.path)._ls() >>> len(entries) > 0 True
- ls(ref='HEAD', *, number=None)[source]¶
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(refspec=None, sha=None, **kwargs)[source]¶
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}'
- class libvcs.cmd.git.GitReflogEntryCmd(*, path, refspec, cmd=None)[source]¶
Bases:
objectRun git commands targeting a specific reflog entry.
Wrap some of git-reflog(1) for specific entry operations.
- Parameters:
Examples
>>> GitReflogEntryCmd( ... path=example_git_repo.path, ... refspec='HEAD@{0}', ... ) <GitReflogEntryCmd HEAD@{0}>
- __init__(*, path, refspec, cmd=None)[source]¶
Wrap some of git-reflog(1) for specific entry operations.
- Parameters:
- Return type:
None
Examples
>>> GitReflogEntryCmd( ... path=example_git_repo.path, ... refspec='HEAD@{0}', ... ) <GitReflogEntryCmd HEAD@{0}>
-
path:
Path¶ Directory to check out
- run(command=None, local_flags=None, *, log_in_real_time=False, check_returncode=None, **kwargs)[source]¶
Run a command against a specific reflog entry.
Wraps git reflog.
- Parameters:
- Return type:
Examples
>>> GitReflogEntryCmd( ... path=example_git_repo.path, ... refspec='HEAD@{0}', ... ).run('show') '...'
- show(*, log_in_real_time=False, check_returncode=None)[source]¶
Show this reflog entry.
Examples
>>> result = GitReflogEntryCmd( ... path=example_git_repo.path, ... refspec='HEAD@{0}', ... ).show() >>> len(result) > 0 True
- delete(*, rewrite=False, updateref=False, dry_run=False, verbose=False, log_in_real_time=False, check_returncode=None)[source]¶
Delete this reflog entry.
- Parameters:
rewrite (
bool) – Adjust subsequent entries to compensate.updateref (
bool) – Update the ref to the value of the prior entry.dry_run (
bool) – Don’t actually delete, just show what would be deleted.verbose (
bool) – Print extra information.log_in_real_time (bool)
check_returncode (bool | None)
- Return type:
Examples
>>> result = GitReflogEntryCmd( ... path=example_git_repo.path, ... refspec='HEAD@{0}', ... ).delete(dry_run=True) >>> 'error' in result.lower() or result == '' True
- class libvcs.cmd.git.GitReflogEntry(sha, refspec, action, message, _cmd=None)[source]¶
Bases:
objectRepresent a git reflog entry.
- Parameters:
sha (str)
refspec (str)
action (str)
message (str)
_cmd (GitReflogEntryCmd | None)
-
_cmd:
GitReflogEntryCmd|None= None¶ GitReflogEntryCmd for operations on this entry
- Type:
Internal
- property cmd: GitReflogEntryCmd¶
Return command object for this reflog entry.