4 ms·
You could just call `git stash` instead of `git reset --hard`. It'll have the same effect on your working directory, while also "backing up" the changes. Stash
by neilparikh 4y ago
You could just call `git stash` instead of `git reset --hard`. It'll have the same effect on your working directory, while also "backing up" the changes.
Stashes could be cleared using a cron job.
- pca006132 4y agoiirc stash works more in a stack like manner? Say if you do git stash, and then do git rebase -i to clean up the history, proceed to write some other features, git stash again to clean it up, etc. Can you recover the files for the first stash?
- amichal 4y agogit stash list?
- Delk 4y agoYes, you can. If you save, apply or pop with git stash with no arguments, it works like a stack by default, but you can also access the other entries. For example `git stash pop stash@{n}`, where n is the index of the entry in the stash "stack", applies the nth stash entry on top of the working tree and then removes it from the stored stashes. The latest entry is at index zero, so stash@{0} would be the last saved/pushed one. You can see a list of saved stashes and their indices with `git stash list`.
- staindk 4y agoAh you can use pop with other stashes too, thanks for the tip... though that feels a bit like a semantic misnomer (? unsure what term would be best to describe what I'm thinking - but 'pop' kind of feels like it should always be applicable only to the top element in a stack. I'd be scared that popping stash@{5} would apply all of stashes 1 to 5 at once lol). I've been using `git stash apply stash@{n}`, which works just fine, but the stash is then not removed from your list and results in clutter.
- Delk 4y ago> though that feels a bit like a semantic misnomer It does, but then, this is the git command-line interface. :) My understanding is that the stash pop command is simply an apply plus the removal of the successfully applied stash. The man page reflects this. It does not pop everything above element in the list.