0

I guess I did something I shouldn't have. I tried to use stash, but thought that I should branch off, and do it there. Anyway, so these are the commands I did:

git branch test     # created my test branch
git checkout test   # moved to my test branch
git status          # showed that the files were still changed.
git stash           # testing stash
git stash list      # showed that the stash was there
git status          # showed that the files were still changed?
git diff            # showed that the differences were only file permissions.
git stash apply     # Tried to get back my changes. States:
                    #   error: Your local changes to the following files would be overwritten by merge:
                    #   ...
                    #   Please, commit your changes or stash them before you can merge.
                    #   Aborting
git commit file -m "- committing test code that doesn't work."
git status          # Shows that it's clean

So, I'm thinking that the problem is that branching and checking out wiped my changes instead of preserving them. Is that correct? If not, can I get my changes back?

Adrian
  • 10,246
  • 4
  • 44
  • 110

1 Answers1

0
git stash apply     # Tried to get back my changes. States:
                    #   error: Your local changes to the following files would be overwritten by merge:
                    #   ...
                    #   Please, commit your changes or stash them before you can merge.
                    #   Aborting
git commit file -m "- committing test code that doesn't work."
git status          # Shows that it's clean

This suggests that the stash wasn't applied (the attempt was aborted because you had local changes that would have been overwritten by the stash).

The last two commands commit the changes that existed in the working directory (at least, I assume they did - you've cut the git add step from your list of commands-run). You never re-apply the stash, so it should still exist.

Check what git stash list says.

From the comment, git stash list says stash@{0}: WIP on test: 0581365 Added. This means you've got a stashed commit, which you can apply (for example git stash apply).

simont
  • 68,704
  • 18
  • 117
  • 136
  • It says: `stash@{0}: WIP on test: 0581365 Added` – Adrian Nov 13 '13 at 07:19
  • @Adrian See my amended answer. – simont Nov 13 '13 at 08:27
  • FYI, the file was already added prior to this set of commands. – Adrian Nov 13 '13 at 17:40
  • Yeah, that's the page where I started to do this. Oh and the file was already added to the repository prior to all of this. The problem is that it's not being applied, so do I get it applied? If I loose the changes, oh well, but I'd like to know just what happened to stop it from happening in the future when I have something more important. – Adrian Nov 13 '13 at 17:47
  • @Adrian what does [`git stash show -p stash@{0}`](http://stackoverflow.com/questions/7677736/git-diff-against-a-stash) say? If the changes you're expecting are shown in the stash diff, and it's still not applying, amending the question with the error or reason the stash isn't applying would be helpful. You can also do a `git checkout ` and examine files that way. – simont Nov 14 '13 at 02:02
  • Ahhh, there's my stuff. :) Now how do I get it out of there? – Adrian Nov 14 '13 at 06:31
  • @Adrian So the `git stash show -p` shows a diff containing your code (and said code is by definition [of being a diff] not contained in the working directory)? In that case, `git stash apply` *should* apply the diff onto the working directory. After applying, `git status` should show the affected files as "changes not staged for commit"; `git add` and `git commit` to get the stashed and applied changes to a commit. I'm assuming you've tried that - what step in the process is failing (and what's the error)? – simont Nov 14 '13 at 06:39