newBike
newBike

Reputation: 15022

revert to previous merged-branch commit without loss any version

My commit history is

A->B->C(head)

If I want to revert to B without losing version C. (make all the data is identical to B)

(But B and C are merged commit )

A->B->C->B(head)

I use the git flow to develop my project

I want to revert to 6450851e7a51f868da414467b42b0c072718f5b9

and do the following command but got an error.

How could I get it ?

(develop)$ git revert 6450851e7a51f868da414467b42b0c072718f5b9
error: Commit 6450851e7a51f868da414467b42b0c072718f5b9 is a merge but no -m option was given.
fatal: revert failed


*   f831a96 - (HEAD, tag: 1.1, origin/master, master) Merge branch 'release/1.1' (7 days ago)
|\
| * 277bafc - Release 1.1 (7 days ago)
| *   57a4374 - Merge branch 'feature/add_expired_time_and_restore_sorting_cart_bug' into develop (7 days ago)
| |\
| | * 3866d1d - Remove the larger input field (7 days ago)
| | * 879c12e - Remove the insert new item at first function (7 days ago)
| | * bbd7b2b - remove the change password function (7 days ago)
| | * bc4a6fa - add expired time functionality (7 days ago)
| |/
| *   6450851 - Merge branch 'feature/readable_format' into develop (7 days ago)
| |\
| | * cac4083 - make the line space in table more dense (7 days ago)

enter image description here

Upvotes: 0

Views: 277

Answers (2)

lrineau
lrineau

Reputation: 6294

As you want to revert a merge, you need to tell git which parent of the merge commit is the mainline you want to preserve:

git revert -m 1 6450851e7a51f868da414467b42b0c072718f5b9

You will find more information here: http://git-scm.com/blog/2010/03/02/undoing-merges.html

Upvotes: 0

We Are All Monica
We Are All Monica

Reputation: 13354

First, if you have merges, then your commit history is more complicated than just A->B->C.

However, hopefully C is not a merge commit. If that's true, then you want to run:

git revert hash-of-commit-C

(git revert takes the hash of the commit to undo, not the commit you want to revert to).

Upvotes: 2

Related Questions