I used magit to store current workspace content to git using z z, which I expected to store my work in a stash. However, process log showed that magit simply did git reset --hard HEAD and created an empty stash. I expected some git stash.

Ok, then I thought I might want to "Save workspace", so I did z w and what magit issued was git checkout -- ., plus empty stash.

Err, ok, maybe I want a "Snapshot"? That did "something", creating an empty stash...

I could not find the issued command in buffer the magit-process buffer of the current repository...

I am confused what is happening here...

PS: I had much luck, that I did not lose my work.

EDIT:

To be more precise: I want to know why I almost lost all changes (all done to already tracked files).

What I learned already is, that magit creates the stashes somehow and then performs reasonable cleanup.

EDIT:

Fault was making process-environment file-local and fiddling with environment, from a .dir-local.el. Lessons learned: Read the docs and don't do that!

  • FYI magit provides a bunch of useful stashing variants that git stash does not provide, and so calling the latter is insufficient. – phils Apr 21 '17 at 15:14
  • Thanks @phil, you're right. Due to my problem I learned another area where magit is cool. – theldoria Apr 21 '17 at 16:06
up vote 3 down vote accepted

Magit does not use git stash to create stashes, because that does not support creating snapshots (which are just like stashes, but their creation does not reset the files in the working tree, which helps keeping timestamp based build systems happy).

Magit's process buffer only shows a subset of the git invocations. More precisely it only shows invocations that were run for side-effects. Also showing commands that were run in order to do something with their output, would be to expensive. But you can show more invoked commands by setting magit-git-debug to t. But unfortunately that doesn't show all commands that are being invoked to create a stash either. That involves some very low-level stuff, and the used functions don't report their output even with magit-git-debug.

The reason you see git reset --hard HEAD when creating a stash is because that's the last step in creating a stash: remove the stashed changes from the working tree. (And because that command is one of those "for side-effects" commands that are reported by default.) If you don't want to remove those changes, then use a "snapshot" variant.

  • Thanks for clarifying that up. That's all good to know, however, what I really wanted to know is why the stashes are all completely empty. I almost lost all changes, they where only recoverable by chance (using emacs undo). – theldoria Apr 21 '17 at 13:05
  • 1
    Regarding the cleanup (which I expect after stashing): magit should probably double check the stashing success before removing all changes. @tarsius What do you think, shall I file a request for that on github? – theldoria Apr 21 '17 at 13:13
  • Yeah, it's probably easier to figure out what went wrong there. – tarsius Apr 21 '17 at 13:22
  • I am currently trying to narrow down the possible cause of the problem. Using Linux instead of Windows, identical emacs config, and fresh repository did not show the issue. So it's probably either related to Windows or the repositories config. – theldoria Apr 21 '17 at 13:44
  • 1
    I found the problem on my side. It was a function, called by .dir-locals.el, which made process-environment local (I know) and changed the environment with setenv-internal. I removed that and everything works. Thanks for your help. – theldoria Apr 21 '17 at 15:57

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.