0

I just did something really stupid and I don't know how to fix it.

It's about git. I created a new project on bitbucket then I cloned it on my local computer. I did some modification and several commits but no push. Then I realized I had to transfer my project to another user. So I transferred my project and updated the link to the remote repository on my local machine. But I did a mistake and I copied a wrong link to another repository. Then I did worse because I didn't realize my mistake. I did a pull. And the pull action merged this other remote repository on my local repository. At this moment I realized my error and I fixed the link of my remote repository. But I cannot do a new push now because if I do a push now I will push my commits but also all file from this other repository.

What can I do do revert a wrong pull ? Or is it possible to only push my specific commits only ?

EDIT -

Bastien Vandamme
  • 17,659
  • 30
  • 118
  • 200
  • 2
    Possible duplicate of [Revert Git repo to a previous commit](http://stackoverflow.com/questions/4114095/revert-git-repo-to-a-previous-commit) – Aaron Critchley Nov 06 '15 at 16:32
  • I pulled many commit that are older that my commit. Revert to MY last commit will not revert the pulled commit done before MY last commit. – Bastien Vandamme Nov 06 '15 at 16:41
  • 2
    Something isn't making sense. How did a push update your local repo? Did you pull them back in afterwards? Do you have a merge commit? Take a look at the git log, you should be able to go to the last commit you did on the current repo. Also does the other repo share a common parent commit as your current one? – Doon Nov 06 '15 at 17:51

1 Answers1

1
  1. Get the commit hash that you had when you were in OK state: you can use "git reflog" and see the 2nd line, that may be your previous "good HEAD". You can use the commit there referenced or "HEAD@{1}" as well.
  2. Do "git reset --hard " to that commit.
  3. If you're happy with your "git log" now, you can push. Double check what you are pushing!

PS: To be really sure what you are pushing you can check:

git fetch
git log HEAD..origin/master #or whatever be your remote branch
Robert
  • 33,429
  • 8
  • 90
  • 94