Revert a git reset hard

Asked

Viewed 3,315 times

3

I did some wrong things while doing some testing and deleted all my files both on site and on github, as I do to reverse and not lose everything?

the commandos I used and I believe that was what messed up everything were:

git checkout --orphan gh-pages

git reset --hard

git commit --allow-empty -m "Initializing gh-pages branch"

git push origin gh-pages

git checkout master
  • First recommend DON’T RUN THE GC, It is highly recommended to expect a response with calm...

  • I used this to reverse a local branch that I had deleted... I’m researching how

  • Does anything here help? https://stackoverflow.com/q/3640764

  • @Jeffersonquesado already tried some things didn’t work out, I think I lost everything anyway =/

1 answer

4


Tidying up this data starts with the git fsck. This command checks the git database to see if everything is right.

its name is derived from the tools used to check sanity in file systems, File System Consistency check

We have several options for this git command:

  • --unreachable for objects not reachable in a traditional way
  • --no-reflogs to ignore the reflog
  • --full have git search in corners other than the default

The following command uses these arguments to look for unreachable things, ignoring the reflog and all that is singing:

git fsck --unreachable --no-reflogs --full
  • Erick, I only saw during the writing of my reply that you had tried these alternatives. If it is not helpful, let me know that I remove the answer

  • I ran this command and returned me some SHA

  • The problem is that I deleted the branch where I had started everything and given push, there is some way to recover this branch?

  • Well, maybe one of these SHA1 is the original master branch commit...

  • Opa hang in there I think I’ve managed to recover with your tip, I’ll evaluate here

  • @Erick of course, you can ask git to list what it knows about each of these SHA1. If it’s a commit, just give it a commit git checkout -b lucky-restore-jeff <luckysha1>, that then branch lucky-restore-jeff will point to this commit

  • 2

    So one of these SHA was a commit ai gave the git Cherry-pick command "SHA", and returned the files ...

  • 2

    I’m happy with the result o/ More careful next time. Whenever I see something like this I get sick, it’s very desperate

  • 1

    I just found a little confused your writing in the reply, I do not know if you are Brazilian maybe can be this rs, but your tip was what helped me, thank you.

  • @Erick is Brazilian and still wrote too informal. Pardon local slang and expressions, I will try to reformulate at another time to a more appropriate language

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.