Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git lab not showing difference in branches after reverting merge commit

I have two branches say master and dev, I merged dev into master w/o merge request on git lab.

Problem: Now if I try to raise merge request on git lab from dev to master, it shows no difference.

Solution tried: I created one more branch from master and reverted the merge commit from that branch using

git revert -m

after doing this when I try to raise merge request on git lab it still says

There isn't anything to merge.

But I can see the difference when I try to compare the branches locally.

Please suggest

like image 903
Harpreet Avatar asked Feb 19 '17 14:02

Harpreet


People also ask

What happens when you revert a merge commit?

On the other hand, reverting a merge commit negates all the changes made by the branch of the specified parent. For instance if after reverting the merge commit(177a8b) in the feature branch, it were merged back to master, it would wipe out the changes (9745432 and b15b045) made in the master branch.

Does git revert affect other branches?

A revert adds another commit, you need to merge that commit into the relevant branches yourself. Revert cannot insert a commit into the history, nor change the original commit, so it affects the branches you want it to affect.

What happens to the branches after merge?

When you're done with a branch and it has been merged into master, delete it. A new branch can be made off of the most recent commit on the master branch. Also, while it is ok to hang onto branches after you've merged them into the master they will begin to pile up.

How do I revert a merge in Git lab?

After the merge request has been merged, use the Revert button to revert the changes introduced by that merge request. After you select that button, a modal appears where you can choose to revert the changes directly into the selected branch or you can opt to create a new merge request with the revert changes.

How do I revert a branch in Git?

If you look at the network tab in gitlab or git log you will see the revert is after the merge. Revert does not rewrite the history, it adds a new commit. Instead of doing a revert use git reset --hard <commit> to reset the master branch to state before the merge and then git push -f.

Can I revert a branch after it has been merged?

Well, yes, because it's already merged. If you look at the network tab in gitlab or git log you will see the revert is after the merge. Revert does not rewrite the history, it adds a new commit. Instead of doing a revert use git reset --hard <commit> to reset the master branch to state before the merge and then git push -f.

How do I revert a merge commit in Git?

You can use Git’s powerful feature to revert any commit by clicking the Revert button in merge requests and commit details. The Revert button is shown only for projects that use the merge method “Merge Commit”, which can be set under the project’s Settings > General > Merge request.

How do I compare two branches in Git?

Getting started with Git and GitLab. To compare branches in a repository: Navigate to your project’s repository. Select Repository > Compare in the sidebar. Select the target repository to compare with the repository filter search box . Select branches to compare using the branch filter search box . Click Compare to view the changes inline:


2 Answers

Well, yes, because it's already merged. If you look at the network tab in gitlab or git log you will see the revert is after the merge. Revert does not rewrite the history, it adds a new commit.

Instead of doing a revert use git reset --hard <commit> to reset the master branch to state before the merge and then git push -f.

like image 191
Jakub Kania Avatar answered Oct 08 '22 06:10

Jakub Kania


Here is a LifeHack:

  1. You do a merge of branch "Task" to the master
  2. Something goes wrong and you press the "revert" button and GitLab makes a new branch with name something like "revert-1" and a merge request for it
  3. You merge branch "revert-1" to the master
  4. Then you make some changes to your branch "Task" and there are no changes when you try to merge it to the master (Oops...)
  5. So you seek for that merge request of branch "revert-1" and press the "revert" button for it - GitLab makes new branch "revert-2" with reverted changes of "revert-1"
  6. Merge "revert-2" into your "Task"
  7. Then merge your "Task" to the master
  8. Congratulations! You're awesome!
like image 34
SteepZero Avatar answered Oct 08 '22 06:10

SteepZero