Is there a way with to prevent “git stash pop” from marking files as modified?

I don’t think so (timestamp is altered, as mentioned in “GIT: Adding Local Changes to Non-Current Branch” for instance). The easiest way would be configure your IDE to refresh automatically. For Eclipse for instance, this would be the setting “Refresh on Access”. Another approach would be to keep another local repo (one where there is … Read more

Stash changes to specific files

You can add the files with changes you want to keep, then stash the rest of the files and clear the stash: git add file2.cpp file2.h file3.cpp git stash –keep-index At this point, you’ve stashed your unwanted changes. If you’d like to permanently get rid of them, run: git stash drop Now you have file2.cpp, … Read more

In git, is there a way to show untracked stashed files without applying the stash?

Untracked files are stored in the third parent of a stash commit. (This isn’t actually documented, but is pretty obvious from The commit which introduced the -u feature, 787513…, and the way the rest of the documentation for git-stash phrases things… or just by doing git log –graph ‘stash@{0}’) You can view just the “untracked” … Read more

How to reverse apply a stash?

According to the git-stash manpage, “A stash is represented as a commit whose tree records the state of the working directory, and its first parent is the commit at HEAD when the stash was created,” and git stash show -p gives us “the changes recorded in the stash as a diff between the stashed state … Read more

How do I name and retrieve a Git stash by name?

To save a stash with a message: git stash push -m “my_stash_name” Alternatively (deprecated since v2.16): git stash save “my_stash_name” To list stashes: git stash list All the stashes are stored in a stack. To pop (i.e. apply and drop) the nth stash: git stash pop stash@{n} To pop (i.e. apply and drop) a stash … Read more

How to recover stashed uncommitted changes

The easy answer to the easy question is git stash apply Just check out the branch you want your changes on, and then git stash apply. Then use git diff to see the result. After you’re all done with your changes—the apply looks good and you’re sure you don’t need the stash any more—then use … Read more