LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Managing branches in Git (https://www.linuxquestions.org/questions/programming-9/managing-branches-in-git-609862/)

Mike_W 12-29-2007 04:11 PM

Managing branches in Git
 
I've just started to use Git, and so far I've found it useful. Naturally, there are a couple of things that have me stumped though:

1) Let's say we have two branches like so:

Code:

A -- B -- D
      \    \
      C -- E

In other words, the bottom branch is based on the top branch, but the bottom branch has a couple of additions. Then, we make a commit to the lower branch:

Code:

A -- B -- D
      \    \
      C -- E -- F

Now, if the patch from E to F was one that we would actually rather like applied to D, how do we do so properly in git? We can't just pull from the bottom branch since that would pull the extra stuff that makes the lower branch distinct from the top branch.

So far, I've just been using git-diff to generate patches and apply them myself, but surely there's a way to do this properly?

2) In a similar situation, we have two branches again:

Code:

A -- B -- D -- F
      \    \ 
      C -- E

We then make a change to the top branch, which we don't want to pull into the lower branch. However, we still want all following patches to be pulled into the lower branch e.g.

Code:

A -- B -- D -- F -- G
      \    \ 
      C -- E

We now want to apply the patch from F to G, but without the patch from D to F. Of course, we can no longer use git pull since this would apply the unwanted patch.

Any help on either of these cases is greatly appreciated.

Mike.

BartTrojanowski 12-30-2007 03:45 PM

git-cherry-pick
 
You want git-cherry-pick.

Code:

A -- B -- D          (work)
      \    \
      C -- E -- F    (master)

Note that I have added labels for the two branches.

Now, to apply the commit F onto the work branch you would:

Code:

git-checkout work
git-cherry-pick F

Note that F is either the SHA1 sum of the last commit on the master branch, or just master since the master branch points to that commit.

After these commands you end up with this graph:

Code:

A -- B -- D -- F'    (work)
      \    \
      C -- E -- F    (master)

Now, F and F' are the same patch, but applied onto different end points.

Mike_W 01-19-2008 03:27 PM

Thanks, that's sorted out problem number one, and problem two isn't all that common, so I can work around it.


All times are GMT -5. The time now is 07:30 PM.