为什么 git checkout master 会重置我的编辑?
基本上,我已经在 master 分支中工作(我没有签出到另一个分支)并且在执行 git add 之后。和 git commit,我不小心运行了 git checkout master,现在当我执行 git Push 时,它说一切都是最新的(但当然不是)。相当奇怪的一个。
Basically, I was working already in the master branch , (I hadn't checked out to another branch) and after doing git add . and git commit, I accidentally ran git checkout master, now when I do git push it says everything is up to date (but ofcourse its not). Quite an odd one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您已经在 master 上并且执行 git checkout master ,则不会发生任何事情,因此您一定做了一些未包含在您的问题中的事情。
执行 gitk --all。您是否在本地 master 或 origin/master 上看到您的提交?如果没有,则执行 git reflog 并查找您的提交。也许您处于分离的 HEAD 状态,因此提交没有保存到任何分支。在这种情况下,请确保您已签出 master 并 gitcherry-pick 。
最坏的情况是你以为你提交了,但你没有,然后你以为你签出了 master,但你实际上签出了你编辑的文件,从而在保存到 git 之前覆盖了你的更改。如果您在转发日志中没有看到任何内容,则可能发生了类似的事情。
If you're already on master and you do git checkout master nothing will happen, so you must have done something that's not included in your question.
Do gitk --all. Do you see your commit either on local master or on origin/master? If not then do git reflog and look for your commit. Maybe you were in a detached HEAD state so the commit didn't get saved to any branch. In that case make sure you have master checked out and git cherry-pick .
Worst case scenario is you thought you committed, but you didn't, and then you thought you checked out master, but you actually checked out the file you edited, thus overwriting your changes before they were saved to git. If you don't see anything in reflog, probably something like that happened.