Hg merge -> revert -> merge - version-control

I've stuck with a small Mercurial problem: I merged a branch A into a branch B and everything succeeded, but after that one of my teammates reverted the branch B back to pre-merge status.
Now I need to merge branch A once again into branch B, but I get the following error:
abort: merging with a working directory ancestor has no effect
How to solve the problem?

You can backout revision that reverted your branch B. This will create new changeset with inverted modifications that was applied in "revert" changeset.

Related

2 diff commit from same branch but diff merge?

I have created a branch and committed to it, got it reviewed and merged with main branch. Now when I try to push another change into another commit with the same branch now I see 2 commits on the branch and if I now merge, the first commit as well as the second will get merged? why is this happening?

Update github branch from another branch

I have created a branch from another branch. Then I come back to previous branch and work on it. Now I have switched to second branch. But this second branch don't have the new changes of first branch. I just want to update the second branch from first branch without deleting any of them.
But this second branch don't have the new changes of first branch
Switching to the second branch alone is not enough for said branch to reflect changes committed in the first branch.
You would need to git merge branch1 or, if you are the only one working on branch2: git rebase branch1 (if you want to keep a linear history).
Then, and only then, would you see branch1 changes in branch2.
⇒ The OP Waqar Ahmed proposes in the comments:
I have solved this issue but checking out branch2 and pull the branch1

Eclipse Git - switch branch without merge

This is maybe a dumb question, but I could not find a way to solve my problem. I am working with Eclipse and Git.
When switching and pulling branches to work on different features, the local commits of the previous branch are added to the commit history of the new branch.
Let say I am working on a branch A, commit twice, then I create from master a branch B, switch to this branch B, pull, and perform one commit. Now my branch B contains the changes made on branch A + the commit made on branch B, making it difficult to create a pull request to merge the change of the only commit B to master.
I would like my local commits/changes to be erased when switching to another branch. How can I do that with Eclipse Git?
After playing around with eclipse, I noticed there was two possible pull actions:
The default one does Fetch + merge, resulting in the mess described in the question
The other option allow you to select Fetch + rebase, to rebase your working directory to the state of the remote branch.
Based on this answer https://stackoverflow.com/a/17324792/10631518 you can even make rebase the default behaviour by running
git config branch.autosetuprebase always

Mercurial: How to ignore multiple heads of a branch when used as ancestor on a closed branch

Another git user confused by Mercurial branches here. I've done something that I can't figure out how to undo and as a result I cannot push my totally unrelated changes. Any help would be appreciated.
Here's the story, I think:
I started working on something on default. I realized this was a mistake as it would become a PR, so the next commit I did on a branch feature1. I then submitted a PR on bitbucket.
I started working on something else, also off of default, this time I was certain to use a branch feature2, and I did purposely "hg up -r ..." with the revision number before my feature1 commit so as not to include that change.
At this point the history looks something like,
-- G (default) - H (feature1)
/
.. D - F (default)
\
-- I - J - K (feature2)
My PR was not accepted, so I close feature1.
There has been development on default in the parent repository, so I hg pull. Now it looks something like,
-- G (default) - H (feature1) [my repository, closed]
/
.. D - F (default)--- L (default) [parent repository]
\
-- I - J - K (feature2) [my repository]
.. plus lots of changes on other branches that I don't know anything about.
But I'm happy with feature2 and I want to make a PR for it, so I try to hg push --new-branch, but I get the message,
abort: push creates new remote head 7a341084eb8a!
Ok, so use hg glog and it appears the checksum corresponds with the parent work, i.e. L in the diagram above. Mercurial seems to be complaining that I have a commit on a closed branch with the branch default that has not been merged into default! But I don't want it to exist anymore! However, I don't want to strip it as then it would make reading the old, closed PR impossible.
If I try to push just my own branch, hg push --new-branch -b feature2, then I get:
abort: push creates new remote head 062efd5d0886!
i.e., same problem but with a different head. This one appears to correspond with the first patch of feature2! That is, I in my diagram.
This makes no sense.. a closed branch is stopping me from pushing the changes on an entirely other branch. Meanwhile I can't figure out what multiple heads it's even talking about when pushing my feature2 branch, since there is really only one feature2. The recommendation is to "merge" before pushing, but I can't even figure out here what to merge. I don't want to merge my rejected change on default, and when I do hg merge default on feature2, thinking maybe I need to take into account the latest upstream changes, this merges G, from my closed branch instead of the upstream head.
So, clearly, I just don't understand Mercurial branches. In git I would just delete the feature1 branch and that would be that. How do I resolve this?
But I'm happy with feature2 and I want to make a PR for it, so I try to hg push --new-branch, but I get the message,
abort: push creates new remote head 7a341084eb8a!
At this point, revision L is the head of branch default, and you are trying to send revision G. Revision G is in the default branch, so you will create another head. The branch feature1 was closed, but not the default branch in the revision G. You can update to revision G, and close the branch there, or merge it with revision L.
If I try to push just my own branch, hg push --new-branch -b feature2,
then I get:
abort: push creates new remote head 062efd5d0886!
If revision I is in the default branch, you have the same problem as above.
If not, try hg push -r <rev number of revision I>.

Changing what branch a merge is on without redoing the merge?

If somebody has merged branch B into branch A, but meant to merge A into B (so that the commit would be on branch B), is there a method I could use to get that merge (and all of it's descendents) into branch B? Besides redoing the merge, which was a considerable amount of work.
The following approach should solve your issue, but is not really 'clean'.
Update to branch B (just before the merge).
Start a new merge with branch A. To avoid any interactivity, you can use 'hg merge --tool internal:local'. The actual merging doesn't matter, as you'll use the results from your previous merge.
Revert to the previous merge: hg revert --all -r OLD_MERGE_CHANGESET
Commit the merge.
Use 'hg rebase' to move all your later commits on top of the correct branch.
Assuming that you’ve just committed the merge, or if not, that the merge changeset 1. has no children and 2. is the parent of your working directory, then:
hg branch B --force
hg commit --amend