stash¶
For git-stash(1).
Overview¶
Manage git stashes using GitStashManager (collection-level)
and GitStashEntryCmd (per-stash operations).
Note
GitStashCmd is the legacy interface. Use git.stashes
(GitStashManager) for the new Manager/Cmd pattern.
Example¶
from libvcs.cmd.git import Git
git = Git(path='/path/to/repo')
# Push changes to stash
git.stashes.push(message='Work in progress')
# List all stashes
stashes = git.stashes.ls()
# Get a specific stash and operate on it
stash = git.stashes.get(index=0)
stash.show()
stash.apply()
stash.drop()
# Clear all stashes
git.stashes.clear()
API Reference¶
Bases:
objectTraverse and manage git stashes with ORM-like filtering via QueryList.
Wrap some of git-stash(1), manager.
Examples
>>> GitStashManager(path=tmp_path) <GitStashManager path=...>
>>> GitStashManager(path=tmp_path).run() 'fatal: not a git repository (or any of the parent directories): .git'
>>> GitStashManager( ... path=example_git_repo.path ... ).run() 'No local changes to save'
Run a command against a git repository’s stash storage.
Wraps git stash.
Examples
>>> GitStashManager(path=example_git_repo.path).run() 'No local changes to save'
Git stash push.
Save local modifications to a new stash entry.
Examples
>>> GitStashManager(path=example_git_repo.path).push() 'No local changes to save'
>>> GitStashManager(path=example_git_repo.path).push(message='WIP') 'No local changes to save'
Git stash clear.
Remove all stash entries.
Examples
>>> GitStashManager(path=example_git_repo.path).clear() ''
List stashes (raw output).
Examples
>>> GitStashManager(path=example_git_repo.path)._ls() []
List stashes.
Returns a QueryList of GitStashEntryCmd objects.
Parses stash list format: -
stash@{0}: On master: message-stash@{0}: WIP on master: commitExamples
>>> GitStashManager(path=example_git_repo.path).ls() []
- Return type:
Get stash entry via filter lookup.
Examples
>>> GitStashManager( ... path=example_git_repo.path ... ).get(index=0) Traceback (most recent call last): exec(compile(example.source, filename, "single", ... return self.ls().get(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "..._internal/query_list.py", line ..., in get raise ObjectDoesNotExist libvcs._internal.query_list.ObjectDoesNotExist
- Parameters:
- Return type:
Bases:
objectRun git commands targeting a specific stash entry.
Lite, typed, pythonic wrapper for git-stash(1) per-entry operations.
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... branch='master', ... message='WIP', ... ) <GitStashEntryCmd path=... index=0>
Run command against a git stash entry.
Wraps git stash.
Git stash show for this stash entry.
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... ).show() 'error: stash@{0} is not a valid reference'
Git stash apply for this stash entry.
Apply the stash without removing it from the stash list.
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... ).apply() 'error: stash@{0} is not a valid reference'
Git stash pop for this stash entry.
Apply the stash and remove it from the stash list.
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... ).pop() 'error: stash@{0} is not a valid reference'
Git stash drop for this stash entry.
Remove this stash from the stash list.
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... ).drop() 'error: stash@{0} is not a valid reference'
Git stash branch for this stash entry.
Create a new branch from this stash entry and apply the stash.
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... ).create_branch('new-branch') 'error: stash@{0} is not a valid reference'
Bases:
objectRun git stash commands (low-level, use GitStashManager for traversal).
Lite, typed, pythonic wrapper for git-stash(1).
Examples
>>> GitStashCmd(path=tmp_path) <GitStashCmd path=...>
>>> GitStashCmd(path=tmp_path).run(quiet=True) 'fatal: not a git repository (or any of the parent directories): .git'
>>> GitStashCmd(path=example_git_repo.path).run(quiet=True) ''
Run a command against a git repository’s stash storage.
Wraps git stash.
Examples
>>> GitStashCmd(path=example_git_repo.path).run() 'No local changes to save'
Git stash list.
Examples
>>> GitStashCmd(path=example_git_repo.path).ls() ''
Push changes to the stash.
Wraps git stash push.
Examples
>>> GitStashCmd(path=example_git_repo.path).push() 'No local changes to save'
>>> GitStashCmd(path=example_git_repo.path).push(path='.') 'No local changes to save'
Git stash pop.
Examples
>>> GitStashCmd(path=example_git_repo.path).pop() 'No stash entries found.'
>>> GitStashCmd(path=example_git_repo.path).pop(stash=0) 'error: stash@{0} is not a valid reference'
>>> GitStashCmd(path=example_git_repo.path).pop(stash=1, index=True) 'error: stash@{1} is not a valid reference'
>>> GitStashCmd(path=example_git_repo.path).pop(stash=1, quiet=True) 'error: stash@{1} is not a valid reference'
>>> GitStashCmd(path=example_git_repo.path).push(path='.') 'No local changes to save'
Git stash save.
Examples
>>> GitStashCmd(path=example_git_repo.path).save() 'No local changes to save'
>>> GitStashCmd(path=example_git_repo.path).save(message="Message") 'No local changes to save'