Previous: , Up: Manipulating   [Contents][Index]


6.12 Stashing

Also see the git-stash(1) manpage.

z (magit-stash)

This transient prefix command binds the following suffix commands along with the appropriate infix arguments and displays them in a temporary buffer until a suffix is invoked.

z z (magit-stash-both)

Create a stash of the index and working tree. Untracked files are included according to infix arguments. One prefix argument is equivalent to --include-untracked while two prefix arguments are equivalent to --all.

z i (magit-stash-index)

Create a stash of the index only. Unstaged and untracked changes are not stashed.

z w (magit-stash-worktree)

Create a stash of unstaged changes in the working tree. Untracked files are included according to infix arguments. One prefix argument is equivalent to --include-untracked while two prefix arguments are equivalent to --all.

z x (magit-stash-keep-index)

Create a stash of the index and working tree, keeping index intact. Untracked files are included according to infix arguments. One prefix argument is equivalent to --include-untracked while two prefix arguments are equivalent to --all.

z Z (magit-snapshot-both)

Create a snapshot of the index and working tree. Untracked files are included according to infix arguments. One prefix argument is equivalent to --include-untracked while two prefix arguments are equivalent to --all.

z I (magit-snapshot-index)

Create a snapshot of the index only. Unstaged and untracked changes are not stashed.

z W (magit-snapshot-worktree)

Create a snapshot of unstaged changes in the working tree. Untracked files are included according to infix arguments. One prefix argument is equivalent to --include-untracked while two prefix arguments are equivalent to --all-.

z a (magit-stash-apply)

Apply a stash to the working tree.

First try git stash apply --index, which tries to preserve the index stored in the stash, if any. This may fail because applying the stash could result in conflicts and those have to be stored in the index, making it impossible to also store the stash’s index there as well.

If the above failed, then try git stash apply. This fails (with or without --index) if there are any uncommitted changes to files that are also modified in the stash.

If both of the above failed, then apply using git apply. If there are no conflicting files, use --3way. If there are conflicting files, then using --3way requires that those files are staged first, which may be undesirable, so prompt the user whether to use --3way or --reject.

Customize magit-no-confirm if you want to always use --3way, without being prompted.

z p (magit-stash-pop)

Apply a stash to the working tree. On complete success (if the stash can be applied without any conflicts, and while preserving the stash’s index) then remove the stash from stash list.

First try git stash pop --index, which tries to preserve the index stored in the stash, if any. This may fail because applying the stash could result in conflicts and those have to be stored in the index, making it impossible to also store the stash’s index there as well.

If the above failed, then try git stash apply. This fails (with or without --index) if there are any uncommitted changes to files that are also modified in the stash.

If both of the above failed, then apply using git apply. If there are no conflicting files, use --3way. If there are conflicting files, then using --3way requires that those files are staged first, which may be undesirable, so prompt the user whether to use --3way or --reject.

Customize magit-no-confirm if you want to always use --3way, without being prompted.

z k (magit-stash-drop)

Remove a stash from the stash list. When the region is active, offer to drop all contained stashes.

z v (magit-stash-show)

Show all diffs of a stash in a buffer.

z b (magit-stash-branch)

Create and checkout a new branch from an existing stash. The new branch starts at the commit that was current when the stash was created.

z B (magit-stash-branch-here)

Create and checkout a new branch from an existing stash. Use the current branch or HEAD as the starting-point of the new branch. Then apply the stash, dropping it if it applies cleanly.

z f (magit-stash-format-patch)

Create a patch from STASH.

k (magit-stash-clear)

Remove all stashes saved in REF’s reflog by deleting REF.

z l (magit-stash-list)

List all stashes in a buffer.

User Option: magit-stashes-margin

This option specifies whether the margin is initially shown in stashes buffers and how it is formatted.

The value has the form (INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH).

  • If INIT is non-nil, then the margin is shown initially.
  • STYLE controls how to format the author or committer date. It can be one of age (to show the age of the commit), age-abbreviated (to abbreviate the time unit to a character), or a string (suitable for format-time-string) to show the actual date. Option magit-log-margin-show-committer-date controls which date is being displayed.
  • WIDTH controls the width of the margin. This exists for forward compatibility and currently the value should not be changed.
  • AUTHOR controls whether the name of the author is also shown by default.
  • AUTHOR-WIDTH has to be an integer. When the name of the author is shown, then this specifies how much space is used to do so.

Previous: Resetting, Up: Manipulating   [Contents][Index]