@@ -584,7 +584,101 @@ <h2>
584
584
branch, do some work in it and then switch back and do some work in our
585
585
master branch, then see how the < code > log</ code > command can help us figure
586
586
out what is happening on each.</ p >
587
-
587
+
588
+ < p > First we'll create a new branch to add the Erlang programming language
589
+ Hello World example - we want to do this in a branch so that we don't
590
+ muddy up our stable branch with code that may not work for a while so we
591
+ can cleanly switch in and out of it.</ p >
592
+
593
+ < pre >
594
+ < b > $ git checkout -b erlang</ b >
595
+ Switched to a new branch 'erlang'
596
+ < b > $ vim erlang_hw.erl</ b >
597
+ < b > $ git add erlang_hw.erl </ b >
598
+ < b > $ git commit -m 'added erlang'</ b >
599
+ [erlang ab5ab4c] added erlang
600
+ 1 files changed, 5 insertions(+), 0 deletions(-)
601
+ create mode 100644 erlang_hw.erl
602
+ </ pre >
603
+
604
+ < p > Since we're having fun playing in functional programming languages we
605
+ get caught up in it and also add a Haskell example program while still in
606
+ the branch named 'erlang'.</ p >
607
+
608
+ < pre >
609
+ < b > $ vim haskell.hs</ b >
610
+ < b > $ git add haskell.hs </ b >
611
+ < b > $ git commit -m 'added haskell'</ b >
612
+ [erlang 1834130] added haskell
613
+ 1 files changed, 4 insertions(+), 0 deletions(-)
614
+ create mode 100644 haskell.hs
615
+ </ pre >
616
+
617
+ < p > Finally, we decide that we want to change the class name of our Ruby
618
+ program back to the way it was. So, we can go back to the master branch
619
+ and change that and we decide to just commit it directly in the master
620
+ branch instead of creating another branch.</ p >
621
+
622
+ < pre >
623
+ < b > $ git checkout master</ b >
624
+ Switched to branch 'master'
625
+ < b > $ ls</ b >
626
+ README ruby.rb
627
+ < b > $ vim ruby.rb </ b >
628
+ < b > $ git commit -am 'reverted to old class name'</ b >
629
+ [master 594f90b] reverted to old class name
630
+ 1 files changed, 2 insertions(+), 2 deletions(-)
631
+ </ pre >
632
+
633
+ < p > So, now say we don't work on the project for a while, we have other
634
+ things to do. When we come back we want to know what the 'erlang' branch
635
+ is all about and where we've left off on the master branch. Just by looking
636
+ at the branch name, we can't know that we made Haskell changes in there, but
637
+ using < code > git log</ code > we easily can. If you give Git a branch name,
638
+ it will show you just the commits that are "reachable" in the history of
639
+ that branch, that is the commits that influenced the final snapshot.</ p >
640
+
641
+ < pre >
642
+ < b > $ git log --oneline erlang</ b >
643
+ < span class ="hl "> 1834130 added haskell</ span >
644
+ ab5ab4c added erlang
645
+ 8d585ea Merge branch 'fix_readme'
646
+ 3cbb6aa fixed readme title differently
647
+ 3ac015d fixed readme title
648
+ 558151a Merge branch 'change_class'
649
+ b7ae93b added from ruby
650
+ 3467b0a changed the class name
651
+ 17f4acf first commit
652
+ </ pre >
653
+
654
+ < p > This way, it's pretty easy to see that we have Haskell code included in
655
+ the branch (as I've highlighted). What is even cooler is that we can
656
+ easily tell Git that we only are interested in the commits that are
657
+ reachable in one branch that are not reachable in another, in other words
658
+ which commits are unique to a branch in comparison to another.
659
+ </ p >
660
+
661
+ < p >
662
+ In this case if we are interested in merging in the 'erlang' branch we
663
+ want to see what commits are going to effect our snapshot when we do
664
+ that merge. The way we tell Git that is by putting a < code > ^</ code > in
665
+ front of the branch that we don't want to see. For instance, if we want
666
+ to see the commits that are in the 'erlang' branch that are not in the
667
+ 'master' branch, we can do < code > erlang ^master</ code > , or vice versa.
668
+ </ p >
669
+
670
+ < pre >
671
+ < b > $ git log --oneline erlang ^master</ b >
672
+ 1834130 added haskell
673
+ ab5ab4c added erlang
674
+ < b > $ git log --oneline master ^erlang</ b >
675
+ 594f90b reverted to old class name
676
+ </ pre >
677
+
678
+ < p > This gives us a nice, simple branch management tool. It allows us to
679
+ easily see what commits are unique to which branches so we know what
680
+ we're missing and what we would be merging in if we were to do a merge.
681
+ </ p >
588
682
589
683
< p class ="nutshell ">
590
684
< b > In a nutshell</ b > you use < code > git log</ code > to list out the commit
0 commit comments