Recent Changes - Search:

Basics

Languages

Tools

OS

Resources

PmWiki

pmwiki.org

edit SideBar

Git /

StashingChanges

If you are in the middle of working on something but need to look at an earlier version or a different branch of the repository, you will need to stash your uncommitted changes before doing so. Stashing changes is done with

git stash

and a list of stashes can be accessed with

git stash list

Stashing changes means that they are temporarily put away for later use, in a way similar to a commit. Once you come back and are ready to work again, you can reapply the changes with

git stash pop StashName.

Unlike branches and earlier commits, stashes are not saved, which means that once popped, they go away. It is not a different form of version control but a quick and dirty way to temporarily put something on hold while looking at something else.

It is also possible to apply a stash, that is, to modify the files, without hiding the commit, with

git stash apply

optionally with the hash or identification of the stash. This enables you to apply the changes, check that they were properly done, and then remove the stash with

git stash drop

with, again, the option to specify stash{n} to specify which stash to drop. Applying a stash and then dropping it is the safer alternative to popping a stash, to use especially if the stash was sizeable.

If you didn't apply then drop, but popped the stash then lost it, it is possible to retrieve the stash by looking for what git calls "dangling" commits:

git fsck --no-reflog

which will return a list of hashes corresponding to commits which aren't tied to anything (ie dangling). Use git diff to figure out which of these is the one you are interested in if there are multiple, then git stash apply hash to apply it.

Edit - History - Print - Recent Changes - Search
Page last modified on May 13, 2022, at 09:49 AM