Mohamed
Mohamed

Reputation: 1

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.

Upvotes: 0

Views: 431

Answers (1)

gtd
gtd

Reputation: 17236

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.

Upvotes: 4

Related Questions