今天在准备提交代码时, 先执行了 webstorm 的 upadte 功能, 执行完之后发现所有新增和有改动的代码都消失了, 直接被覆盖了. webstorm event log 里提示:
- Local changes were not restored
- Before update your uncommitted changes were saved to stash.
- Update is not complete, you have unresolved merges in your working tree
- Resolve conflicts, complete update and restore changes manually.
大致意思是本地 merge 失败, 本地的改动被保存到一个 stash 存档里
解决方案:
查看存档列表: Git stash list
读最新存档: Git stash pop
读指定存档: Git stash apply stash@{存档编号}
如: Git stash apply stash@{0}
但是读取存档时依旧报错, 之后我再执行 Git add ., 然后执行 Git commit, 最后再执行上述读取存档操作就成功了, 被覆盖的代码也恢复了.
所以以后提交代码时一定要先 commit, 再 push
来源: http://www.jianshu.com/p/2fb3f6e9c44d