tags:

views:

41

answers:

1

Are these the same thing? If so, why are there so many terms?!

Also, I know there is this thing called git stash, which is a place where you can temporarily store changes to your working copy without committing them to the repo. I find this tool really useful, but again, the name is very similar to a bunch of other concepts in git -> this is very confusing!!

+4  A: 

The index/stage/cache are the same thing - as for why some many terms, I think that index was the 'original' term, but people found it confusing, so the other terms were introduced. And I agree that it makes things a bit confusing sometimes at first.

The stash facility of git is a way to store 'in-progress' work that you don't want to commit right now in a commit object that gets stored in a particular stash directory/database). The basic stash command will store uncommitted changes made to the working directory (both cached/staged and uncached/unstaged changes) and will then revert the working directory to HEAD.

It's not really related to the index/stage/cache except that it'll store away uncommitted changes that are in the cache.

This lets you quickly save the state of a dirty working directory and index so you can perform different work in a clean environment. Later you can get back the information in the stash object and apply it to your working directory (even if the working directory itself is in a different state).

The official git stash manpage has pretty good detail, while remaining understandable. It also has good examples of scenarios of how stash might be used.

Michael Burr
git stash is different from the others : it is more like an 'anonymous commit'
Peter Tillemans
@Peter - I tried to address the stash bit more correctly (I mistakenly read it initially as something about the 'stage').
Michael Burr
@Michael Thanks! One point I hope you'll clarify: the end of paragraph 2 says stash stores changes in the "cache", but doing git stash seems to include unstaged changes as well. Is this just another confusion over terminology, or did you really mean that git stash only stores staged changes??
allyourcode
@allyourcode: In one of my interim edits, I tried to make clear that both staged and unstaged changes are *included* in the stash. But it looks like I accidentally dropped some stuff and made the answer less clear. Hopefully that's fixed now.
Michael Burr
@Michael I think the part where it says changes "that are in the cache" in paragraph 3 could be misleading. If I understand git stash correctly, I think that phrase should be dropped.
allyourcode
@allyourcode: but all uncommitted changes - both ones that are unstaged or currently staged - are put into the stash. Paragraph 3 is intended to emphasize that - is it confusing the issue instead? Should I just get rid of the whole sentence? (feel free to edit yourself)
Michael Burr
@Michael your answer says only "changes that are in the cache" get saved to the stash i.e. stashed. What you mean is that _all uncommitted changes_ get stashed, not just the ones in the cache/staging area/index.
allyourcode