Thursday, January 24, 2013

"git stash save --patch" considered harmful

so you've been editing and it's been a few minutes or hours since your last git commit. you run your test case and bam, it fails !!! your working tree changes touch multiple systems ... you want to isolate the changes to see which one broke things before you commit. the obvious answer seems to be git stash -p (aka git stash save --patch). you mark all the changes that you want to stash and try your test case again. you make a few changes and want to pop the stash nqzero> git stash save -p nqzero> git stash pop error: Your local changes to the following files would be overwritten by merge: nutrweb/web/js/diary.js Please, commit your changes or stash them before you can merge. Aborting nqzero> git add -u nqzero> git stash pop # hard to recover if there are conflicts if there aren't any conflicts this is the bee's knees. but if there are conflicts, there's no obvious way to undo the merge (ie un-pop the stash) - the index has been corrupted. any suggestions ? without this, git stash save --patch considered harmful, ie it's very easy to lose changes


git stash create a backup before popping the stash. maybe git should do this for any merge with a dirty tree nqzero> tmp=$(git stash create) nqzero> git stash pop Auto-merging nutrweb/web/js/diary.js CONFLICT (content): Merge conflict in nutrweb/web/js/diary.js nqzero> git reset --hard nqzero> git checkout $tmp -- .

No comments: