-1

Very time I hit git stash it is changing my files to their state in the previous commit. Why is this happing and how did stop this?

  • Does this answer your question? [Stash changes while keeping the changes in the working directory in Git](https://stackoverflow.com/questions/17843384/stash-changes-while-keeping-the-changes-in-the-working-directory-in-git) – JDB Mar 10 '20 at 20:28
  • no. changing my branch files to local masters contents – Snigdha Reddy Pulim Mar 10 '20 at 20:50
  • You'll have to provide more information then. `git stash` should remove all uncommitted changes from your working directory and restore to the previous commit. The changes are stored in your stash (you can get them back via `git stash pop` or `git stash apply`). However, your original question says nothing about master, just "previous commit", which is what `stash` is supposed to do. – JDB Mar 10 '20 at 20:53
  • What exactly is it that you expect/want it to do? – Calum Halpin Mar 10 '20 at 21:47
  • its resolved. My local master was throwing conflicts (I think I made changes in my local master manually). I created a new local master so it's fine now – Snigdha Reddy Pulim Mar 11 '20 at 10:09

1 Answers1

0

[Ev]ery time I hit git stash it is changing my files to their state in the previous commit.

That's what it's supposed to do. What git stash does is commit your work (into two special temporary commits called a "stash"; these commits are not on any branch, making it easy to switch to another branch and recover them), then do a git reset --hard. The git reset --hard resets your index and work-tree to match the current commit.

If you don't want that, don't use git stash.

Note that you can have git stash check out the committed index content after / instead-of doing a hard-reset. I believe this option is intended to allow pre-commit hooks to run code-checking operations on the files that would be committed by git commit. The option for this is -k (as in git stash -k). There are a number of minor flaws with this strategy; see How do I properly git stash/pop in pre-commit hooks to get a clean working tree for tests?

torek
  • 448,244
  • 59
  • 642
  • 775