Undoing a git pull and it's effects on the history

Issue

Here is my sad story

Today I made the mistake of pulling from a different Repository into mine. I am working on Repository A and I pulled the contents of Repository B into A. I did it because I wanted some files from that Repository.

After that I pushed my repository to remote.

My problem is not my code because both repositories are different. But the problem is the history.

Now my remote Repository which can be seen by the public has all the history of commits from Repository B mixed with my commits in the log.

How can I remove those commits from the history LOG?

Is there a way to kinda reset my repository to it’s state like yesterday ? Would that cause the commits from Repository B in my history to disappear ?

I tried to reset the Merge, Use Re-base and Cherry-pick but the history wasn’t removed in either case.

Solution

Thank you everyone. I’ve solved my problem. I managed to solve it with reference to different articles and questions.

I will explain the answer here along with things I’ve learned through my struggle.

To begin with, in order to selectively remove commits from history that are scattered around the best way Can be found in the answer to this question:

Specifically the answer by Charles Bailey. The closest to this answer was Stuart.

Note: Reverting a commit doesn’t remove it from history, Reset does.

As for my particular situation I thought I have to follow the previous method for every commit that I don’t want but actually the answer was simpler.

In my situation I had to reset git to the commit just before I pulled Repository B and it has to be done for all branches. Once this is done all the undesired commits from B disappeared from my history.

Another Interesting thing to mention is that using git Cherry-Pick or Revert on many commits isn’t as straight forward as it sounds from online articles, least for me.

Answered By – Professor NEO

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published