Back

Explore Courses Blog Tutorials Interview Questions
+3 votes
2 views
in DevOps and Agile by (19.7k points)

develop branch

--> dashboard (working branch)

I use git merge --no-ff develop to merge any upstream changes into dashboard

git log:

commit 88113a64a21bf8a51409ee2a1321442fd08db705

Merge: 981bc20 888a557

Author: XXXX <>

Date:   Mon Jul 30 08:16:46 2012 -0500

    Merge branch 'develop' into dashboard

commit 888a5572428a372f15a52106b8d74ff910493f01

Author: root <[email protected]>

Date:   Sun Jul 29 10:49:21 2012 -0500

    fixed end date edit display to have leading 0

commit 167ad941726c876349bfa445873bdcd475eb8cd8

Author: XXXX <>

Date:   Sun Jul 29 09:13:24 2012 -0500

The merge had about 50+ commits in it, and I am wondering how to just revert the merge so dashboard goes back to the state pre-merge

The second part of this is, if I dont do merge with --no-ff, I don't get the commit 'Merge branch 'develop' into dashboard' .. How would I roll that merge back?

2 Answers

+1 vote
by (29.3k points)

Run the following command: 

git reset --merge ORIG_HEAD

The reference ORIG_HEAD will point to the original commit from before the merge.

Here, in the command mentioned above, --merge option has nothing to do with the merge. It is almost like git reset --hard ORIG_HEAD command, but safer since it doesn't touch uncommitted changes.

In addition to that if you do a fast forward merge then you can use git revert to go back to the previous commit:

 git reset --hard <commit_before_merge>

you can get the commit id from git log and git reflog and if you can't find the commit id then you can do:

git reset --hard HEAD@{1}

As mentioned above in this answer.

0 votes
by (62.9k points)

This command is used even when you did a fast-forward merge,  use git reset to get back to the previous state:

git reset --hard <commit_before_merge>

You can find the <commit_before_merge> with git reflog, git log, or if you're feeling the Moxy (and haven't done anything else ):

git reset --hard HEAD@{1}

Refer to this answer to know what is fast-forward merge here 

Related questions

+1 vote
1 answer
+1 vote
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...