简体   繁体   中英

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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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