0

I added my code in git using command "git add ." Unfortunately, I pushed my code into git without commit to git. Then, I tried to checkout to main branch, it gave me an warning. But I checked out to main branch forcefully. After that, I went back to my branch and I lost my last added code.

Is there any way to recover my lost code?

2

1 Answer 1

-2

You must make a commit before you can push. But in your case you can try using git reflog - as this will show you the recent reference changes.

And then you can see the output of your commits or references which might help you to get your lost data.

Refer to this doc.

And since you pushed your changes without commit, Your local data is not pushed, nor lost. It is still there at local branch. You can check that by doing -

git status

Not the answer you're looking for? Browse other questions tagged or ask your own question.