annedroiid
annedroiid

Reputation: 6637

Does git stash stash all changes or just uncommitted ones

If I stash changes using git, will it only stash uncommitted files, or will it stash everything that hasn't been pushed to git?

Upvotes: 1

Views: 178

Answers (3)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520948

The answer to your question is that Git will stash everything which has not been committed to your local branch.

When you do a git stash, it actually makes two temporary commits. The first one contains the files which you have staged (i.e. by doing git add on them). The second one actually contains your working directory files.

When you do a git stash apply, Git will reinstate the working directory. However, if you do git stash apply --index, then it will also try to reinstate the index (i.e. your staged files).

So git stash cleans the slate, and leaves both your stage and working directory in the state they were at your most recent commit.

Upvotes: 2

intboolstring
intboolstring

Reputation: 7100

From the git stash documentation:

Stashing takes the dirty state of your working directory – that is, your modified tracked files and staged changes – and saves it on a stack of unfinished changes that you can reapply at any time. Source

Upvotes: 0

paxdiablo
paxdiablo

Reputation: 881203

It will stash the dirty state of your working directory, specifically tracked files that have been modified and changes that have been staged but not yet committed.

It is not necessary to save committed files since, well, they've been committed. So if, by "pushed to git", you mean local commits that have been pushed to a mirror/origin repo, they won't be saved either (because they've already been committed).

Upvotes: 1

Related Questions