Studyon Minte9.com
Git




Undo branch merge



1) Undo last merge (with multiple commits)

        $ git reset --hard origin/master

        --------     

	$ mkdir www && cd www
	$ echo 1 > index.htm
	$ echo 2 > x.htm
	$ git init
	$ git add .
	$ git commit -m "m1"

	$ cd ..
	$ git clone www user1
	$ cd user1/

	/user1 (master)
	$ ls
	index.htm  x.htm

	/user1 (master)
	$ git checkout -b dev
	$ ls
	index.htm  x.htm

	/user1 (dev)
	$ rm x.htm

	/user1 (dev)
	$ git commit -a -m "m2"

	/user1 (dev)
	$ echo 3 > index.htm
	$ git commit -a -m "m3"

	/user1 (dev)
	$ echo 4 > index.htm
	$ git commit -a -m "m4"

	$ git checkout master

	/user1 (master)
	$ ls
	index.htm  x.htm

	/user1 (master)
	$ git merge dev
	Updating b957a73..10685aa
	Fast-forward
	 index.htm | 2 +-
	 x.htm     | 1 -
	 2 files changed, 1 insertion(+), 2 deletions(-)
	 delete mode 100644 x.htm

	/user1 (master)
	$ ls
	index.htm

	/user1 (master)
	$ git status
	# On branch master
	# Your branch is ahead of 'origin/master' by 3 commits.

	/user1 (master)
	$ git reset --hard origin/master
	HEAD is now at b957a73 m1

	/user1 (master)
	$ ls
	index.htm  x.htm

	/user1 (master)
	$ less index.htm
	1

2) Undo last merge:

        $ git reset --hard HEAD~1

        --------------------

         $ git reset --hard HEAD~5 (go back 5 commits)

        --------------------

        (master)
	$ git merge dev

	$ less example.txt
	<<<<<<< HEAD
	master line
	=======
	dev line 2
	>>>>>>> dev

	(master|MERGING)
	$ git merge dev -X theirs
	error: 'merge' is not possible because you have unmerged files ...
	
		// Undo merge one step
	$ git reset --hard HEAD~1
	HEAD is now at d5f8b30 m

	$ git status
	# On branch master
	nothing to commit, working directory clean


http://stackoverflow.com/questions/2389361/undo-a-git-merge