6 ms·
I still save changes to a file if I switch/merge while having a bigger changeset as I use PHPStorm and it caused me a semi heart attack at least 3 times with th
by jefozabuss 4y ago
I still save changes to a file if I switch/merge while having a bigger changeset as I use PHPStorm and it caused me a semi heart attack at least 3 times with the “unstashing failed“ error (that also removed it from the stash at the same time)
- Cederfjard 4y agoIf a change has ever been committed or stashed (which is basically also committing, just not on a branch), it can always be recovered, at least until garbage collection is run - check out the reflog. Of course, if it hasn't been, then you can lose it.
- nicoburns 4y agoYeah, working out which stash contains your work can be quite tricky though! As they are not named by default.
- vbernat 4y agoYou can add a tag to the change you want to keep. Whatever you do, you can recover it (git reset --hard tag). Once you are done, remove the tag. Otherwise, there is the reflog, like mentioned in a sister comment.
- rubyist5eva 4y agostandard branches can serve this purpose
- rr888 4y agoThe best thing about Jetbrains IDEs is local file history - so you dont have to rely on git - you can still see file history and directory history to restore commits and deleted files. Saved me many times.
- felixthehat 4y agoVS Code added that feature too recently, very nice addition https://code.visualstudio.com/updates/v1_44#_timeline-view https://code.visualstudio.com/updates/v1_44#_timeline-view
- rr888 4y agoThanks I didn't even know that was there, this will help me. It looks like its files only, not directories which is important to get accidentally deleted files.
- speed_spread 4y agoLocal history is great and I dont understand why it's separate from the undo stack, which is limited in size (by default?). Actually, both could be integrated with SCM as fine grained autocommits + eventual squash on manual checkpoint / push.
- nicoburns 4y agoThe other option here is to do a "WIP" (work in progress) commit. Which you can undo (moving the files back into the staging area) with `git reset HEAD^` once you switch back to the branch. Annoying that this is necessary - it would be great if git stash was as robust - but this won't lose your work.
- guitarbill 4y agoYou can also use `git stash apply` (which doesn't pop the stash), followed by maybe merging, and finally a `git stash drop`.
- GauntletWizard 4y agoYou can also use the git reflog to get the recently dropped stash commit's sha, and then check out the files that you miss.