6

I've accidentally cloned (or pulled, I don't remember) another repo into my project repo, and now I see something like +1500 foreign commits, starting from year 2011. I don't know how to simply revert it, because these commits are braided into mine.

Good thing is I haven't pushed it yet, but I have some changes in my work which I would like to preserve. How can I do this?


@edit The accepted answer doesn't preserve my work, but it can be simply solved by following these steps: move the modified files into some safe place → revert → move them back into reverted repo → make a new commit out of them.

jligeza
  • 4,544
  • 6
  • 23
  • 31

1 Answers1

5

If you haven't made any other changes after that, you can follow this steps:

  1. Run git reflog. This will give you a log of the actions done by you on the repo
  2. Pick the log just before the pull. If it is the second last commit you can run

    git reset --hard HEAD@{2}

    to restore your repo to a state just before you pulled your repo

TheGeorgeous
  • 3,927
  • 2
  • 20
  • 33