Since merge and rebase are currently not implemented, what's the recommended way to merge changes from another branch into your active branch using go-git?
For example, suppose our master branch had two commits (m1 and m2).
master m1 -- m2 -- m3
|
feature m2 -- f1 -- f2
combined m1 -- m2 -- m3 -- ? <= what command(s) to merge/squash ?
At that time, we created a feature branch based on the master branch, whose last commit was m2.
We implemented a new feature, f1, that should only exist in the feature branch at this time.
At the same time, our master branch is evolving. Another developer pushed commit m3 to the master branch.
After that time, we continued working on our feature branch and committed those changes in commit f2.
How can we combine our feature branch changes (f1, f2) back into our master branch (m3) ?
(What commands would you execute to perform the merge operation?)
Related
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
Contributing to a public project on Github, I made a fork.
Then I created a new branch (b1) to commit some features and I sent a pull request.
Then I did the same for completely different features: create a new branch (b2 from master), commit some modifications and send a pull request.
While I am waiting for my 2 pull requests to be accepted, I would like to use those modifications which are in branches b1 and b2.
What is the best/easy way to achieve that?
Merging b1 and b2 into master? But master won't be the same as upstream/master and if I create new branched they will include changes from b1 and b2
Create a new temporary branch to merge b1 and b2? But I need to keep this branch up to date with master until all my pull requests will be accepted
Create a new temporary branch to merge b1 and b2?
Yes: you should not modify a branch in use in the original repo, and always isolate your work in a dedicated branch.
If at any time you want to keep that new integration branch (for b1+b2) up-to-date compared to upstream/master, simply rebase it on top of a refreshed upstream/master:
cd /path/to/my/repo
git remote add upstream /url/of/original/repo
git checkout b1_b2
git fetch upstream
git rebase upstream/master
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>.
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
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.