LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-29-2007, 04:11 PM   #1
Mike_W
LQ Newbie
 
Registered: Dec 2007
Posts: 12

Rep: Reputation: 0
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.
 
Old 12-30-2007, 03:45 PM   #2
BartTrojanowski
LQ Newbie
 
Registered: Dec 2007
Posts: 1

Rep: Reputation: 0
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.
 
Old 01-19-2008, 03:27 PM   #3
Mike_W
LQ Newbie
 
Registered: Dec 2007
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks, that's sorted out problem number one, and problem two isn't all that common, so I can work around it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can ping but cannot browse from branches(other subnets) franlinux Linux - Networking 3 09-03-2007 07:18 AM
cannot browse from branches(other subnets) franlinux Linux - Networking 1 08-30-2007 02:37 PM
About Debian branches... ? Deeze Debian 2 03-08-2005 08:27 AM
KMail is a git acid_kewpie Linux - General 0 09-15-2001 01:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration