Git and working on multiple branches

I have a couple of Git branches: “experimental”, “something” and “master”.

I switched to the "experimental" branch. I noticed a mistake that is not related to "experimental" and refers to changes that were made to "something." How to fix it?

I think that I should switch to "something", fix the error, fix, and then return to the "experimental". How should I accept a minor change from “something” and apply it to both the “owner” and the “experimental” one, so that I don’t need to correct the error again when I switch to these branches?

+42
git version-control branch
Aug 26 '09 at 11:22
source share
6 answers

Two solutions that you can use are no longer mentioned: use the topic branch or use the cherry picker .




Branch Branch Solution

In the decision section of the branch , you switch to the "something" branch, create a branch to fix the error, for example. "something-bugfix", merge this branch into "something" (bug fix), and then merge this branch into "experimental".

$ git checkout -b something-fix something [edit, commit] $ git checkout something $ git merge something-fix $ git checkout experimental $ git merge something-fix [fix conflicts if necessary and commit] 

See also Resolving conflicts / dependencies between branches earlier and Never merge backwards , and maybe also Fix blog posts from Unio C Hamano (git maintainer) in another thread .




Cherry-picking bugfix error

The cherry picking solution is useful if you later noticed that the fix you created (for example, in development branches) would also be useful on another branch (for example, stable branch). In your case, you will send the fix to the "something" branch:

 $ git checkout something [edit, edit, edit] $ git commit $ git checkout experimental 

Then you noticed that the patch that you posted in the something branch should also be on the experise branch. Suppose that this fix was fixed with "A" (for example, "something" if you did nothing on top of "something", but it could be, for example, "something" 2 or "c84fb911"):

 $ git checkout experimental $ git cherry-pick A 

(you can use the --edit option for git cherry-pick if you want to edit the commit message before proceeding with the error received with the cherry).

+53
Aug 27 '09 at 10:21
source share

You can:

  • stash or commit changes you used in the experimental branch
  • checkout something
  • (optional) bisect to find the error
  • commit changes
  • checkout experimental

and then:

  • rebase something if you need a clean commit schedule (if you expose this repository and you are interested)

or

  • merge something if you don't like the "presentation" :)
+5
Aug 26 '09 at 11:30 a.m.
source share

since your experimental branch has functions from something , you must do one of:

  • combine something in the experimental after fixing the mistakes there.
  • reinstall pilot on top of something
+2
Aug 26 '09 at 11:29
source share

If you don't advance too much in 'master', just switch to the experimental one and run git master merge. If you do, I think the git cherry-pick 'command is your friend.

0
Aug 26 '09 at 11:25
source share

Your branches are somehow connected as follows:

master> something> experimental

This is if you are really going to combine something into a master.

I could, if possible, fix it on top of the wizard, and then reinstall the rest on top of the wizard. But I just like the reboot. Or you can fix it there and then merge that way.

master> something> experimental

but if something is a simple topic thread, I would not do it. Here it sounds like your "next host candidate"

0
Aug 26 '09 at 11:26
source share

If you can unite, do it. If you do not want to combine something in other branches, then correct the error and cherry pick, which are fixed in each of the other branches.

0
Aug 26 '09 at 11:34
source share



All Articles