3

I am in a bit of a quandary. I accidentally merged code between two Git repositories. For whatever reasons, the repo names were same and one of the repo's URL had changed before I came to know of it. So I ended up merging code from two different projects. Here is the illustration from the repository commits.

Merged repo

I have not named any branches (have been working on HEAD all along). How do I delete one of the commits (specifically the orange one)?

Nilesh C
  • 697
  • 2
  • 7
  • 17

1 Answers1

2

You can do:

git reset --hard 628612ac

If you are sure you don't have anything in the current working copy that you will need. This will put the HEAD to the commit you had before the merge. Nothing is actually deleted - the other commits become unreachable and will be garbage collected sometime in the future.

Another option is to use git-revert:

git revert -m 1 e90aeed8

This will keep your history. It creates a new commit that reverts everything that e90ae... did.

Here's a good read about the subject: https://www.kernel.org/pub/software/scm/git/docs/howto/revert-a-faulty-merge.txt

And also here: http://git-scm.com/2010/03/02/undoing-merges.html

1615903
  • 32,635
  • 12
  • 70
  • 99
  • Thanks!! git revert did the trick locally and git reset --hard worked on the remote repo. The links are very helpful indeed! – Nilesh C May 20 '13 at 04:52