简体   繁体   English

恢复分支上未提交的更改

[英]Recover uncommited changes on a branch

I start to work on some changes on my master branch and realize that this is not a quick fix and I will need more time to do my fix.我开始在我的主分支上进行一些更改,并意识到这不是一个快速修复,我需要更多时间来完成我的修复。 So I save my work in a different branch as described here with:所以我将我的工作保存在不同的分支中,如下所述

git checkout -b newClientID

I didn't commit my change there, since I wanted to make more relevant progress.我没有在那里提交我的更改,因为我想取得更相关的进展。 Then I switch to my master and reset it然后我切换到我的master并重置它

git checkout master
git checkout -- .

When I switch back to my branch newClientID I realize that my uncommitted changes have been lost.当我切换回我的分支newClientID我意识到我未提交的更改已丢失。 Any chance to recover them?有机会挽回吗?

If you don't commit and reset the working tree, it's lost forever.如果您不提交并重置工作树,它将永远丢失。

Next time, commit often, maybe more than necessary and eventually squash commits with interactive rebasing before pushing to remote.下一次,经常提交,可能是不必要的,并最终在推送到远程之前通过交互式 rebase 压缩提交。

By commiting, eg with git commit -m wip , I find it less error prone than git stash because it's all too easy to git stash pop in the wrong branch.通过提交,例如使用git commit -m wip ,我发现它比git stash更不容易出错,因为在错误的分支中git stash pop太容易了。

The same happened to me.我也遇到了同样的情况。 this is a silly answer but it actually worked.这是一个愚蠢的答案,但它确实有效。 I went to my files with the lost changes, ctrl+z and all the changes appeared.我带着丢失的更改去了我的文件,ctrl+z 并且所有更改都出现了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM