From 8195eb02e132c90ed7a5e6575d9b4707fa2ab1a5 Mon Sep 17 00:00:00 2001 From: Scott Chacon Date: Fri, 4 Jun 2010 16:37:58 +0200 Subject: [PATCH] basically finished up the branching section --- _layouts/reference.html | 1 - branching/index.html | 96 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/_layouts/reference.html b/_layouts/reference.html index 183dd2b..2de1967 100755 --- a/_layouts/reference.html +++ b/_layouts/reference.html @@ -61,7 +61,6 @@
  • checkout
  • merge
  • log
  • -
  • reset
  • diff --git a/branching/index.html b/branching/index.html index ce3f117..6796bbe 100644 --- a/branching/index.html +++ b/branching/index.html @@ -584,7 +584,101 @@ b7ae93b added from ruby branch, do some work in it and then switch back and do some work in our master branch, then see how the log command can help us figure out what is happening on each.

    - + +

    First we'll create a new branch to add the Erlang programming language + Hello World example - we want to do this in a branch so that we don't + muddy up our stable branch with code that may not work for a while so we + can cleanly switch in and out of it.

    + +
    +$ git checkout -b erlang
    +Switched to a new branch 'erlang'
    +$ vim erlang_hw.erl
    +$ git add erlang_hw.erl 
    +$ git commit -m 'added erlang'
    +[erlang ab5ab4c] added erlang
    + 1 files changed, 5 insertions(+), 0 deletions(-)
    + create mode 100644 erlang_hw.erl
    +
    + +

    Since we're having fun playing in functional programming languages we + get caught up in it and also add a Haskell example program while still in + the branch named 'erlang'.

    + +
    +$ vim haskell.hs
    +$ git add haskell.hs 
    +$ git commit -m 'added haskell'
    +[erlang 1834130] added haskell
    + 1 files changed, 4 insertions(+), 0 deletions(-)
    + create mode 100644 haskell.hs
    +
    + +

    Finally, we decide that we want to change the class name of our Ruby + program back to the way it was. So, we can go back to the master branch + and change that and we decide to just commit it directly in the master + branch instead of creating another branch.

    + +
    +$ git checkout master
    +Switched to branch 'master'
    +$ ls
    +README  ruby.rb
    +$ vim ruby.rb 
    +$ git commit -am 'reverted to old class name'
    +[master 594f90b] reverted to old class name
    + 1 files changed, 2 insertions(+), 2 deletions(-)
    +
    + +

    So, now say we don't work on the project for a while, we have other + things to do. When we come back we want to know what the 'erlang' branch + is all about and where we've left off on the master branch. Just by looking + at the branch name, we can't know that we made Haskell changes in there, but + using git log we easily can. If you give Git a branch name, + it will show you just the commits that are "reachable" in the history of + that branch, that is the commits that influenced the final snapshot.

    + +
    +$ git log --oneline erlang
    +1834130 added haskell
    +ab5ab4c added erlang
    +8d585ea Merge branch 'fix_readme'
    +3cbb6aa fixed readme title differently
    +3ac015d fixed readme title
    +558151a Merge branch 'change_class'
    +b7ae93b added from ruby
    +3467b0a changed the class name
    +17f4acf first commit
    +
    + +

    This way, it's pretty easy to see that we have Haskell code included in + the branch (as I've highlighted). What is even cooler is that we can + easily tell Git that we only are interested in the commits that are + reachable in one branch that are not reachable in another, in other words + which commits are unique to a branch in comparison to another. +

    + +

    + In this case if we are interested in merging in the 'erlang' branch we + want to see what commits are going to effect our snapshot when we do + that merge. The way we tell Git that is by putting a ^ in + front of the branch that we don't want to see. For instance, if we want + to see the commits that are in the 'erlang' branch that are not in the + 'master' branch, we can do erlang ^master, or vice versa. +

    + +
    +$ git log --oneline erlang ^master
    +1834130 added haskell
    +ab5ab4c added erlang
    +$ git log --oneline master ^erlang
    +594f90b reverted to old class name
    +
    + +

    This gives us a nice, simple branch management tool. It allows us to + easily see what commits are unique to which branches so we know what + we're missing and what we would be merging in if we were to do a merge. +

    In a nutshell you use git log to list out the commit