简体   繁体   English

为什么 git 结账大师会重置我的编辑?

[英]Why does git checkout master resets my edits?

Basically, I was working already in the master branch, (I hadn't checked out to another branch) and after doing git add.基本上,我已经在 master 分支中工作了(我还没有签出到另一个分支)并且在添加 git 之后。 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).和 git 提交,我不小心运行了 git 结帐主机,现在当我执行 git 推送时,它说一切都是最新的(但当然不是)。 Quite an odd one.很奇怪的一个。

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.如果您已经在 master 上并且您执行 git checkout master 什么都不会发生,所以您必须做了一些未包含在您的问题中的事情。

Do gitk --all.做 gitk --all。 Do you see your commit either on local master or on origin/master?您是否在本地 master 或 origin/master 上看到您的提交? If not then do git reflog and look for your commit.如果没有,请执行 git reflog 并查找您的提交。 Maybe you were in a detached HEAD state so the commit didn't get saved to any branch.也许你在一个分离的 HEAD state 所以提交没有保存到任何分支。 In that case make sure you have master checked out and git cherry-pick.在这种情况下,请确保您已签出主控并 git 挑选。

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.最坏的情况是您认为您已提交,但您没有提交,然后您认为您签出了 master,但实际上您签出了您编辑的文件,因此在将更改保存到 git 之前覆盖了您的更改。 If you don't see anything in reflog, probably something like that happened.如果您在 reflog 中没有看到任何内容,则可能发生了类似的事情。

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

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