简体   繁体   中英

Lost work doing a git checkout, how can I get it back

So... not sure how it happened, but I had been working in a branch a I made a couple changes, ran git add -A and then git commit (with a comment). Did that a few times, and then when I went to push up all the changes to the branch I was in, I got a message that said that the branch was already up to date. I couldnt figure out what the heck was going on, so I checked back out the branch and it overwrote everything.

Stranger still, now all the commits I made are gone when I run git log.

Any way I can get it all back? Or am I SOL and have to figure out why the heck it kicked me out of my branch for some reason?

You are in a detached HEAD (see " Why did my Git repo enter a detached HEAD state? ").
You can confirm it with a git status .

Simply start by making a branch where you are:

git branch tmp

See here one way to fix it (and keeping your commits) , if you want to push aBranch :

git checkout aBranch
git merge tmp

aBranch should now include the commits you did, and you should be able to push it.

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