├── .gitignore
├── Makefile
├── README.mkd
├── TODO
├── ack.tex
├── afterhours1.tex
├── afterhours2.tex
├── afterhours3.tex
├── afterhours4.tex
├── afterhours5.tex
├── afterhours6.tex
├── afterhours7.tex
├── afterhours8.tex
├── builder.sh
├── chap1.tex
├── chap2.tex
├── chap3.tex
├── chap4.tex
├── chap5.tex
├── chap6.tex
├── chap7.tex
├── chap8.tex
├── chap9.tex
├── gitt.cls
├── gitt.tex
├── html
├── base-foot.html
├── base-head.html
├── chap-foot.html
├── chap-head.html
├── chap-style.css
├── download.html
├── feedback.html
├── images
│ ├── back.jpg
│ ├── background.jpg
│ ├── corner.png
│ ├── fade_bot.png
│ ├── fade_right.png
│ ├── git.png
│ ├── git_logo.png
│ ├── git_logo_new.png
│ ├── leave_feedback.png
│ ├── next.png
│ ├── next_day.png
│ ├── pix.gif
│ ├── pointer.gif
│ ├── prev.png
│ ├── previous_day.png
│ ├── read_now.png
│ ├── slide1.png
│ ├── tick.png
│ └── tick2.png
├── index.html
├── legal.html
├── stylesheet.css
└── sub.html
├── images
├── bcover-new.pdf
├── combinedcover.pdf
├── f-af2-d1.pdf
├── f-af2-d2.pdf
├── f-af2-d3.pdf
├── f-af4-d2.pdf
├── f-af5-d1.png
├── f-af5-d2.png
├── f-af5-d3.png
├── f-af7-d1.png
├── f-af7-d2.png
├── f-af7-d3.png
├── f-af7-d4.png
├── f-af7-d5.png
├── f-af7-d6.png
├── f-w1-d1.pdf
├── f-w1-d2.pdf
├── f-w1-d3.pdf
├── f-w2-d1.pdf
├── f-w4-d1.pdf
├── f-w4-d2.pdf
├── f-w4-d3.pdf
├── f-w4-d4.pdf
├── f-w4-d5.pdf
├── f-w4-d6.pdf
├── f-w5-d1.png
├── f-w5-d10.png
├── f-w5-d11.png
├── f-w5-d12.png
├── f-w5-d13.png
├── f-w5-d14.png
├── f-w5-d15.png
├── f-w5-d16.png
├── f-w5-d17.png
├── f-w5-d18.png
├── f-w5-d19.png
├── f-w5-d2.png
├── f-w5-d3.png
├── f-w5-d4.png
├── f-w5-d5.png
├── f-w5-d6.png
├── f-w5-d7.png
├── f-w5-d8.png
├── f-w5-d9.png
├── f-w7-d1.pdf
├── f-w7-d2.pdf
├── f-w7-d3.pdf
├── f-w7-d4.pdf
├── f-w7-d5.pdf
├── f-w7-d6.pdf
├── f-w7-d7.pdf
├── fcover-new.pdf
├── raster
│ ├── af7-d1.png
│ ├── af7-d2.png
│ ├── af7-d3.png
│ ├── af7-d4.png
│ ├── af7-d5.png
│ ├── af7-d6.png
│ ├── gg1.png
│ ├── gg2.png
│ ├── gg3.png
│ ├── w5-d1.png
│ ├── w5-d11.png
│ ├── w5-d13.png
│ ├── w5-d14.png
│ ├── w5-d15.png
│ ├── w5-d16.png
│ ├── w5-d17.png
│ ├── w5-d18.png
│ ├── w5-d19.png
│ ├── w5-d2.png
│ ├── w5-d4.png
│ ├── w5-d6.png
│ ├── w5-d7.png
│ └── w5-d8.png
└── source
│ ├── af2-d1.svg
│ ├── af2-d2.svg
│ ├── af2-d3.svg
│ ├── af4-d2.svg
│ ├── bcover-new.png
│ ├── bcover-new.svg
│ ├── cog.svg
│ ├── combinedcover.svg
│ ├── fcover-epub.png
│ ├── fcover-new.svg
│ ├── w1-d1.pdf
│ ├── w1-d1.svg
│ ├── w1-d2.pdf
│ ├── w1-d2.svg
│ ├── w1-d3.pdf
│ ├── w1-d3.svg
│ ├── w2-d1.pdf
│ ├── w2-d1.svg
│ ├── w4-d1.svg
│ ├── w4-d2.svg
│ ├── w4-d3.svg
│ ├── w4-d4.svg
│ ├── w4-d5.svg
│ ├── w4-d6.svg
│ ├── w5-d1.svg
│ ├── w5-d8.svg
│ ├── w7-d1.svg
│ ├── w7-d2.svg
│ ├── w7-d3.svg
│ ├── w7-d4.svg
│ ├── w7-d5.svg
│ ├── w7-d6.svg
│ └── w7-d7.svg
├── index.tex
├── intro.tex
├── scripts
├── htmlbuild.py
├── munger.py
└── test.sh
└── setup.tex
/.gitignore:
--------------------------------------------------------------------------------
1 | *.aux
2 | *.log
3 | *.toc
4 | *.out
5 | *.idx
6 | *.ilg
7 | *.ind
8 | *.pyc
9 | gitt.pdf
10 | print.pdf
11 | scripts/outputs
12 | site/
13 | gitt-com.pdf
14 | build/
15 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # Location of build dir
2 | BUILD_DIR=build
3 |
4 | BUILD_DIR_IMAGES=$(BUILD_DIR)/images/chaps
5 |
6 | # Location of website files
7 | SITE_DIR=site
8 |
9 | # Location of website images
10 | SITE_IMAGES_DIR=$(SITE_DIR)/images
11 |
12 | SITE_CHAP_IMAGES_DIR=$(SITE_IMAGES_DIR)/chaps
13 |
14 | SITE_STYLE_DIR=$(SITE_DIR)/style
15 |
16 | # List of targets that are not files
17 | .PHONY: all quick clean web print pdf screen quickpdf cleantmp cleanpdf cleanimages html htmlimages cleansite
18 |
19 | all: pdf cleantmp
20 | quick: quickpdf cleantmp
21 | clean: cleantmp cleanpdf
22 | web: images html
23 |
24 | # Generate a print version PDF (for lulu.com)
25 | print:
26 | xelatex '\def\mediaformat{print}\input{gitt}'
27 | makeindex gitt
28 | xelatex '\def\mediaformat{print}\input{gitt}'
29 | xelatex '\def\mediaformat{print}\input{gitt}'
30 |
31 | # Generate the PDF (on-screen version)
32 | pdf:
33 | xelatex '\def\mediaformat{screen}\input{gitt}'
34 | makeindex gitt
35 | xelatex '\def\mediaformat{screen}\input{gitt}'
36 | xelatex '\def\mediaformat{screen}\input{gitt}'
37 |
38 | # An alias for generated the PDF
39 | screen: pdf
40 |
41 | # Quickly update the PDF. Will not update the index or cross-references
42 | quickpdf:
43 | xelatex gitt
44 |
45 | # Remove the temporary files generated by LaTeX
46 | cleantmp:
47 | rm -f *.aux *.log *.out *.toc *.idx *.ind *.ilg
48 |
49 | # Remove the generated PDF
50 | cleanpdf:
51 | rm -f gitt.pdf
52 | rm -f print.pdf
53 |
54 | # Remove the generated website images
55 | cleanimages:
56 | @rm -f $(SITE_IMAGES_DIR)/*.png
57 |
58 | # Clean up generated site files
59 | cleansite:
60 | @rm -fr $(SITE_DIR)
61 | @rm html/nav.html
62 |
63 | cleanbuild:
64 | @rm -fr $(BUILD_DIR)
65 |
66 | site: html htmlimages
67 |
68 | baseconvert: $(BUILD_DIR) $(BUILD_DIR_IMAGES) htmlimages
69 | @python scripts/htmlbuild.py alltex
70 | @python scripts/htmlbuild.py baseconvert
71 | @python scripts/htmlbuild.py baseconcat
72 | @cp -r site/images $(BUILD_DIR)
73 | @cp -r images/source/*.svg $(BUILD_DIR_IMAGES)
74 |
75 | baseconvert-mobi: $(BUILD_DIR) $(BUILD_DIR_IMAGES) htmlimages
76 | @python scripts/htmlbuild.py alltex
77 | @python scripts/htmlbuild.py baseconvert mobi
78 | @python scripts/htmlbuild.py baseconcat
79 | @cp -r site/images $(BUILD_DIR)
80 | @cp -r images/source/*.svg $(BUILD_DIR_IMAGES)
81 |
82 | baseconvert-epub: $(BUILD_DIR) $(BUILD_DIR_IMAGES) htmlimages
83 | @python scripts/htmlbuild.py alltex
84 | @python scripts/htmlbuild.py baseconvert epub
85 | @python scripts/htmlbuild.py baseconcat
86 | @cp -r site/images $(BUILD_DIR)
87 | @cp -r images/source/*.svg $(BUILD_DIR_IMAGES)
88 |
89 | epub: baseconvert-epub
90 | @ebook-convert build/complete.html build/complete.epub --chapter '//*[name()="h1"]' --authors 'Peter Savage' --title 'Git In The Trenches' --cover images/source/fcover-epub.png
91 |
92 | epub-view: epub
93 | @ebook-viewer build/complete.epub
94 |
95 | mobi: baseconvert-mobi
96 | @ebook-convert build/complete.html build/complete.mobi --chapter '//*[name()="h1"]' --authors 'Peter Savage' --title 'Git In The Trenches' --cover images/source/fcover-epub.png
97 |
98 | mobi-view: mobi
99 | @ebook-viewer build/complete.mobi
100 |
101 | # Convert TeX to HTML
102 | html: $(SITE_IMAGES_DIR)
103 | @touch html/nav.html
104 | @cp html/stylesheet.css $(SITE_DIR)/
105 | @cp html/index.html $(SITE_DIR)/
106 | @python scripts/htmlbuild.py simple index
107 | @python scripts/htmlbuild.py simple feedback
108 | @python scripts/htmlbuild.py simple download
109 | @python scripts/htmlbuild.py simple legal
110 | @python scripts/htmlbuild.py alltex
111 | @python scripts/htmlbuild.py allchaps
112 | @python scripts/htmlbuild.py allafterhours
113 | @python scripts/htmlbuild.py intro
114 | @python scripts/htmlbuild.py setup
115 |
116 | # Get a list of all SVG images
117 | IMAGES=$(shell ls images/source/*.svg)
118 |
119 | # Generate list of images required for the website
120 | SITEIMAGES=$(shell for IMAGE in $(IMAGES); do echo "$$(basename $${IMAGE} .svg).png"; done)
121 |
122 | # Generate PNG file from SVG file
123 | %.png: images/source/%.svg $(SITE_IMAGES_DIR) $(SITE_CHAP_IMAGES_DIR) $(BUILD_DIR_IMAGES)
124 | inkscape -f $< -D -w 400 -e $(SITE_CHAP_IMAGES_DIR)/f-$(shell basename $< .svg).png >/dev/null
125 | inkscape -f $< -D -l $(BUILD_DIR_IMAGES)/f-$(shell basename $<)
126 |
127 | # Convert all images
128 | htmlimages: $(SITEIMAGES) $(SITE_CHAP_IMAGES_DIR)
129 | @cp images/f-w5-d1.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d1.png
130 | @cp images/f-w5-d2.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d2.png
131 | @cp images/f-w5-d3.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d3.png
132 | @cp images/f-w5-d4.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d4.png
133 | @cp images/f-w5-d5.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d5.png
134 | @cp images/f-w5-d6.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d6.png
135 | @cp images/f-w5-d7.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d7.png
136 | @cp images/f-w5-d8.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d8.png
137 | @cp images/f-w5-d9.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d9.png
138 | @cp images/f-w5-d10.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d10.png
139 | @cp images/f-w5-d11.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d11.png
140 | @cp images/f-w5-d12.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d12.png
141 | @cp images/f-w5-d13.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d13.png
142 | @cp images/f-w5-d14.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d14.png
143 | @cp images/f-w5-d15.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d15.png
144 | @cp images/f-w5-d16.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d16.png
145 | @cp images/f-w5-d17.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d17.png
146 | @cp images/f-w5-d18.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d18.png
147 | @cp images/f-w5-d19.png $(SITE_CHAP_IMAGES_DIR)/f-w5-d19.png
148 | @cp images/f-af7-d1.png $(SITE_CHAP_IMAGES_DIR)/f-af7-d1.png
149 | @cp images/f-af7-d2.png $(SITE_CHAP_IMAGES_DIR)/f-af7-d2.png
150 | @cp images/f-af7-d3.png $(SITE_CHAP_IMAGES_DIR)/f-af7-d3.png
151 | @cp images/f-af7-d4.png $(SITE_CHAP_IMAGES_DIR)/f-af7-d4.png
152 | @cp images/f-af7-d5.png $(SITE_CHAP_IMAGES_DIR)/f-af7-d5.png
153 | @cp images/f-af7-d6.png $(SITE_CHAP_IMAGES_DIR)/f-af7-d6.png
154 | @cp images/f-af5-d1.png $(SITE_CHAP_IMAGES_DIR)/f-af5-d1.png
155 | @cp images/f-af5-d2.png $(SITE_CHAP_IMAGES_DIR)/f-af5-d2.png
156 | @cp images/f-af5-d3.png $(SITE_CHAP_IMAGES_DIR)/f-af5-d3.png
157 | @cp html/images/* $(SITE_IMAGES_DIR)/
158 |
159 | # Make directories
160 | $(SITE_DIR):
161 | @mkdir -p $(SITE_DIR)
162 |
163 | $(SITE_STYLE_DIR):
164 | @mkdir -p $(SITE_STYLE_DIR)
165 |
166 | $(SITE_IMAGES_DIR):
167 | @mkdir -p $(SITE_IMAGES_DIR)
168 |
169 | $(SITE_CHAP_IMAGES_DIR):
170 | @mkdir -p $(SITE_CHAP_IMAGES_DIR)
171 |
172 | $(BUILD_DIR):
173 | @mkdir -p $(BUILD_DIR)
174 |
175 | $(BUILD_DIR_IMAGES):
176 | @mkdir -p $(BUILD_DIR_IMAGES)
177 |
--------------------------------------------------------------------------------
/README.mkd:
--------------------------------------------------------------------------------
1 | # Git In The Trenches
2 |
3 | Git In The Trenches, or GITT is designed to be a book that focusses on teaching people to use Git by associating with scenarios that are experienced by a fictional company called Tamagoyaki Inc.
4 | Through reading about their day to day lives, the reader will learn not only how to use Git, but why version control systems are important and how to implement them within an organisation.
5 |
6 | # Book Contents
7 |
8 | The summary below shows a list of already complete chapters and items which are pending. GITT now covers all 21 of the most commonly used Git commands.
9 |
10 | 1. Analysing VCS requirements
11 | 2. Initialising a repo, adding files, removing files, committing, resetting
12 | 3. Logging, diffing, tagging, viewing historical data
13 | 4. Branching, merging, deleting branch, recovering branch, dealing with conflicts
14 | 5. GUI usage
15 | 6. Stashing, Cloning
16 | 7. Networking, Rebasing
17 | 8. Patching, Bisecting, Filterbranching, subtree, modules
18 |
19 | After Hours
20 |
21 | 1. History of version control, svn, cvs, git
22 | 2. Simple Git internals, how commits are stored
23 | 3. Indepth look at diff and how tags are stored
24 | 4. Merging algorithms
25 | 5. Splitting up commits, line by line, hunk committing
26 | 6. Push and pull settings, reference discussion
27 | 7. Instaweb
28 | 8. Hooks
29 |
30 | # Building the Book
31 |
32 | GITT is written using the LaTeX language to be able to generate the PDFs easily and without artifacts.
33 | If you wish to read GITT whilst it is in development phase, you have 3 options.
34 |
35 | 1. Read the LaTeX source, which really isn't as bad as it sounds
36 | 2. Use `make pdf` to use latex to build the pdf, you will need to have `pdflatex` installed for this
37 | * For ubuntu users, run `sudo apt-get install texlive-latex-base texlive-latex-extra texlive-fonts-recommended texlive-xetex ttf-linux-libertine` to get `xelatex` and the other files required to build
38 | 3. An older PDF version of the book can be found here
39 |
40 | # Publishing
41 |
42 | It is the intention of the author to make the book available freely online, and eventually offer a printed version via a self publishing site online.
43 | If someone out there thinks the book would do well to be published by a proper print publisher and can help make this happen, please get in contact.
44 | However the book will remain free online no matter what.
45 |
46 | # Contributing
47 |
48 | The GITT project would love for people to branch off and make alterations to the text, or even start to create translations.
49 | Currently the book is written in LaTeX, but it isn't hard to learn.
50 | You can see the source files in plain text and edit them quite easily.
51 | Also, we are looking for situations in which you may have found yourself whilst using Git, whether you managed to resolve them or not.
52 | GITT is rather scenario based sometimes, so we need situations in which to place the employees at Tamagoyaki Inc.
53 | Spelling fixes are always welcome, as are general comments on the text itself.
54 |
55 | Anyone who contributes will be added to the Acknowledgement section if they wish it.
56 | If I miss you out, please do not be offended, just nudge me gently :)
57 |
--------------------------------------------------------------------------------
/TODO:
--------------------------------------------------------------------------------
1 | General spelling check/grammer check
2 | Sanity on git commands check
3 | I think I am using 1.7.1 Git
4 | Need to figure out what is in 1.7.4 if there are any differences
5 |
6 | Get vetting from someone on the history of version control systems
7 | Come up with more breakout boxes :)
8 | Come up with more items for terminology
9 |
10 | %git log -p
11 |
12 | %git show master:
13 | %git diff -- stylesheet.css master:stylesheet.css
14 |
15 | % git show v1.0.0^{tree}
16 |
17 | %wmctrl -r Gui -e 0,0,0,811,500
18 |
19 | Neeeed to talk about .gitignore
20 |
21 | Create and place nice icons in top left corner of breakout boxes
22 |
23 |
--------------------------------------------------------------------------------
/ack.tex:
--------------------------------------------------------------------------------
1 | % ack.tex - Acknowledgements
2 | \chapter{Acknowledgements}
3 | \section{``A Huge Thank You''}
4 |
5 | \subsection{Proofing and Ideas}
6 | These people gave their time and effort to do forking and proofing, and giving marvellous suggestions about the book during development:
7 |
8 | Johan Sageryd
9 |
10 | Og Maciel
11 |
12 | Alistair Buxton
13 |
14 | Miia Ranta (Myrtti)
15 |
16 | Hassan Williamson (HazRPG)
17 |
18 | (Synth\_sam)
19 |
20 | Jonas Bushart
21 |
22 | \subsection{\LaTeX{} Support}
23 | These people provided invaluable \LaTeX{} support:
24 |
25 | Johan Sageryd
26 |
27 | Kevin Godby
28 |
29 | Matthew Johnson
30 |
31 | Ben Clifford
32 |
33 | \subsection{Git Support}
34 | Thank you to all these guys too:
35 |
36 | \#git on freenode.net
37 |
38 | GitHub.com for hosting the Git repository of GITT
39 |
40 | Wikipedia.org for providing information on the history of version control systems
41 |
42 | %\index{git!git test@\textbf{git testbol}}
43 | %\index{git!git tootesting}
44 | %\indexref{git!git tootling}
45 | %\indexcom{git!git rebase}{git rebase}
46 |
--------------------------------------------------------------------------------
/afterhours1.tex:
--------------------------------------------------------------------------------
1 | % afterhours1.tex - Afer Hours Week 1
2 | \chapter{After Hours Week 1}
3 | \section{``History Lesson''}
4 | \subsection{A Brief History of Version Control}
5 | \subsubsection{The Very Early Days}
6 | Version control systems have been around for forty years (2011 at the time of writing).
7 | During this time they have undergone an intense amount of change and have evolved into some of the most incredibly powerful tools utilised in software development today.
8 | Chances are that in the early days you will have started off storing different versions of your source code and documents in separate files and folders.
9 | You may have even archived them off to compressed storage files, like zip or tar.
10 | Rest assured, you are not the first person to do this, and in 1972, someone called Marc J.\ Rochkind, decided to create system for storing revisions of documents and source code.
11 |
12 | The system Marc created was called SCCS and stood for Source Code Control System, in essence probably the most apt description for what we mainly use a version control system for today.
13 | SCCS was originally written for an operating system called OS/360 MVT and was later ported to C, and was used as the most dominant version control system for UNIX, until ten years later, when RCS was introduced.
14 |
15 | \subsubsection{Time To Move On}
16 | In 1982, Walter F.\ Tichy released RCS, standing for Revision Control System.
17 | It was intended to be a free and offer more functionality than SCCS.
18 | RCS is still being maintained, as part of the GNU project, and at the time of writing is about to have its first new release, version 5.8, in over fifteen years.
19 |
20 | However, RCS, like its predecessor SCCS, has no way of dealing with groups of files.
21 | Essentially, each file has its own repository which is stored near to the file under a different name.
22 | Whilst rather advanced, with primitive forms of branching, the interface, commands and version numbering have been described by some as rather cumbersome.
23 | Enter some successors.
24 |
25 | CVS (Concurrent Versions System) was created in 1986, and began life as a set of shell scripts to operate on multiple files, using RCS to perform the actual repository management.
26 | As development continued, this way of working was dropped and CVS began operating on files itself, evolving into a version control system in its own right.
27 | The current iteration of CVS was released in 1989 and on November 1 1990, version 1.0 was released to the Free Software Foundation for distribution.
28 |
29 | CVS did not version file renames or moves at all as at the time, re-factoring - a process of modifying code to improve some non-functional attributes of the software, was often avoided and so the feature was not required.
30 | CVS also did not support atomic commits.
31 | An atomic commit is used by more modern version control systems to safe guard the database.
32 | In essence atomic committing is the act of applying multiple changes in a single operation.
33 | If any of the changes do not apply correctly, all others are reverted and the commit is aborted.
34 | When designing CVS this was not seen as an obstacle, as it was thought by the developers that a server and network should have enough resilience that it would never crash whilst committing.
35 |
36 | Whilst active development of CVS has apparently ceased, as of May 2008, it is worth taking note that CVS defined the model for branching that was included and refined in almost all version control systems since.
37 |
38 | \subsubsection{Offering Commercial Support}
39 | Now that version control was advanced enough and people had begun to rely on VCSs in general, commercial offerings began to spring up.
40 | Three prominent systems that were released within a short time of each other; ClearCase, VSS and Perforce.
41 | All three of these are proprietary systems which were developed and filled a gap in the market for commercially supported systems.
42 |
43 | VSS, originally developed by One Tree Software for several platforms, was continually developed by Microsoft, who bought One Tree Software in 1994, with the one caveat that Microsoft ceased development of all VSS on all platforms other than Windows.
44 | VSS integrated into Visual Studio, Microsoft's Integrated Development Environment.
45 | VSS has now ceased development, but ClearCase, now developed by a division of IBM, and Perforce are still being actively developed and maintained.
46 |
47 | \subsubsection{The Millennium}
48 | The millennium brought with it a new breed of version control systems.
49 | Subversion, or SVN as it is colloquially known as, was developed primarily to be a replacement and mostly compatible successor to CVS.
50 | SVN was first released in 2000 and by 2001 was able to sufficiently host its own source code due to its own advancement.
51 | In November 2009 Subversion was accepted into the Apache group and is currently developed and maintained by its community and by several commercial entities.
52 |
53 | Subversion brought things to the table that previous version control systems did not.
54 | As it was released as free software, in the same vein as CVS, it was widely adopted by the open source community and later into commercial environments for its vastly improved feature set.
55 | For a start SVN offers true atomic commits.
56 | This gave it a definite advantage over CVS as it was seen as a truly robust alternative.
57 |
58 | It also brought in features like the tracking of files through renames and moves, including their entire version history and the versioning of symbolic links.
59 | SVN moved with the times and introduced many other sought after features, such as HTTP serving, cheaper branching, efficient network operation and native support for binary files.
60 |
61 | As with all version control systems, there are aspects that people dislike.
62 | In Subversion, people often find the implementation of tags -- that is names that point to specific points in the history of a repository, an issue.
63 | In SVN, a tag is actually a branch.
64 | What makes this different to other systems such as Git and its predecessor CVS, which literally point to a specific commit in the tag, SVN actually creates a snapshot of the file system.
65 | Although it employs relatively cheap branching which is lightweight on the repository, the tagging model used can be incredibly heavyweight on the client.
66 |
67 | Another issue with the tagging model in SVN is that it holds no history information.
68 | This makes it impossible, for example, to take two tags and try to find out all logged commits that occurred from one to the other.
69 | This is the difference between using a copy as a tag, and implementing a reference.
70 | Tags should also be read-only implicitly by their very nature, they should refer to a point in history.
71 | However as tags are implemented as branches in SVN this is not the case.
72 |
73 | \subsubsection{Introducing the Linus Factor}
74 | The Linux kernel was at one point maintained under a source control system called BitKeeper.
75 | The decision, in 2002, to use BitKeeper for the management of the Linux kernel source was rather controversial, the main opposition being that BitKeeper was a proprietary system that was offered by BitMover.
76 | At the time, BitMover offered certain open source projects the opportunity to use BitKeeper at no cost, so long as the community developers did not engage in the creation of a competing tool.
77 |
78 | In April 2005, BitKeeper withdrew the free license that it had granted to the open source communities, after allegations of reverse engineering by some parties on an unrelated project.
79 | Due to the way BitKeeper worked, and decisions made regarding licensing it became impossible for several key developers, and according to some reports including Linus himself, to actually own even a commercial version of BitKeeper.
80 |
81 | It was due to these circumstances, that Linus Torvalds himself, decided to begin writing his own version control system that would enable him to have all of the features that he had had available to him with BitKeeper, the most important of these seemingly being a distributed environment.
82 | Linus decided on a set of criteria, which along with a distributed environment, also included a robust safeguard against corruption, be it accidental, or malicious, and very high performance.
83 |
84 | Git development began on the 3rd of April 2005, and by April the 7th, the project had been announced and was already able to host itself.
85 | On June 16th, the release of the Linux kernel version 2.6.12 was managed by Git.
86 | Junio Hamano, who had been a major contributor to the project, took over maintenance of Git in July, and by December had released version 1.0 to the community.
87 |
88 | Interestingly enough, another project was also created as a result of this chain of events.
89 | Mercurial or Hg as it is often known, is reported to have begun development on April 19th of the same year and was started by Matt Mackall with largely the same goals as Git.
90 | Though Git was chosen to be the version control system used by the Linux kernel, Mercurial is actively used by many other projects and shares a very similar design and concept to Git.
91 |
92 | \subsubsection{Design Changes}
93 | Git has some features which should be discussed here as many of them are different to every other version control system.
94 | Perhaps one of the most important of these is the very strong emphasis on non-linear development.
95 | Git provides many tools with which to work with many branches and merges, with a core principal being that changes will often be passed around more than they will be written.
96 |
97 | Git is very fast.
98 | Though for certain operations it may be slower than some of its peers, Git has been consistently proven to be faster than most.
99 | This design implementation was essential as the Linux kernel is indeed a very large project.
100 |
101 | When developing systems that offer any kind of security to an end user, it is essential to provide a way of auditing the history of the code, to ensure that no tampering has taken place.
102 | Due to the way that Git is implemented, each SHA-1 hash, used to identify a particular commit, depends on the entire history of the repository.
103 | What does this mean to someone viewing the repository? Once the repository is published, it is impossible for someone to tamper with the history without someone noticing.
104 | This is called cryptographic authentication of history.
105 |
106 | Of course the most important feature, and one which will be discussed in great detail later in the book, is that of distributed development.
107 | The emphasis on non-linear development and the implementation of very cheap and fast branching, makes Git one of the best version control systems on the market for distributed development.
108 |
109 | As mentioned previously every version control system has advantages and disadvantages and it would not be fair to make out that Git was without flaws.
110 | Some that have been mentioned by people over the years are its particular steep learning curve for basic understanding.
111 | Whilst it is agreeable to some degree, it is largely due to the fact that Git is a distributed version control system and inherently these systems are more complex in their implementation that others.
112 | Another bug bear of some people, is the fact that Git will not track empty directories.
113 |
114 | \subsubsection{Wrapping Up}
115 | Though there are many other version control systems out there that are being actively developed, such as Bazaar, Plastic and Darcs, to name but a few, we are going to end our historical tale here and continue with learning more about the Git version control system.
116 | There is a plethora of information available on the Internet about version control, so if you want to find more information about any of the systems mentioned here, that would probably be the best place to start.
117 |
--------------------------------------------------------------------------------
/afterhours3.tex:
--------------------------------------------------------------------------------
1 | % afterhours3.tex - Afer Hours Week 3
2 | \chapter{After Hours Week 3}
3 | \section{``A Closer Look At Diffs and Tags''}
4 | \subsection{The Diff Utility}
5 | \index{diff!algorithm}We learnt in \emph{Week 3} how to work with a diff, and what a diff actually represents.
6 | It is interesting to note how old the \texttt{diff} utility actually is and how it works.
7 | The diff algorithm was developed in the early 1970s and the research published in 1976, by Douglas McIlroy, who wrote the original diff utility and James Hunt.
8 | The algorithm we use today to perform diffs has become known as the Hunt-McIlroy after the research papers authors.
9 |
10 | In essence the task of calculating a diff is that of finding the differences between two files on a line by line basis.
11 | Mathematically, this can be described as the LCS or Longest Common Subsequence problem, which is a classic computer science problem.
12 |
13 | Though we are not going to go into the problem in great detail, it is useful to know what actually happens at this level.
14 | Essentially you have two sequences, for now we are going to simplify the problem and work on a string of letters.
15 |
16 | Old string:
17 | \begin{code}
18 | a b c d e j k l m p r s
19 | \end{code}
20 |
21 | New string:
22 | \begin{code}
23 | a c d f g h i j n o p t u
24 | \end{code}
25 |
26 | The challenge is to find the longest sequence of items that is present in both of the strings above.
27 | This new sequence is found by deleting items from the first and second set until all that remains is a sequence of common items.
28 |
29 | In our example case, this is as follows
30 | LCS string:
31 | \begin{code}
32 | a c d j p
33 | \end{code}
34 |
35 | Comparing this to each of our strings above, it is easy to generate a diff.
36 | If the items are present in the \emph{Old string}, but not in the LCS string then they must have been deleted.
37 | Conversely if they are present in the \emph{New string}, but not the LCS, then they must have been additions.
38 | Putting this into practice in our example and marking deletions with \texttt{-} and additions with \texttt{+}, we get the following:
39 |
40 | Diff string:
41 | \begin{code}
42 | b e fghi klm o rs tu
43 | - - ++++ --- + -- ++
44 | \end{code}
45 |
46 | The actual algorithm for generating the LCS and the subsequent diff is too complex to describe here and is out of the scope of this book.
47 | This section was included to give you some idea of how Git performs some of its actions internally.
48 |
49 | \subsection{More about tags}
50 | \index{tagging!internals}Tags can actually do a little more than just hold a single identifier to a specific commit.
51 | A tag can also have a log message with it, similar to the commit objects we discussed earlier.
52 | In order to invoke this option, we need to use the \texttt{git tag -m 'message'} option.
53 | This will allow us to supply a message to be stored along with the tag.
54 | Let us see how this works in practice.
55 |
56 | Firstly we can use the \texttt{git tag} command to show all tags that are currently in the repository.
57 |
58 | \begin{code}
59 | john@satsuki:~/coderepo$ git tag
60 | v0.9
61 | v1.0a
62 | john@satsuki:~/coderepo$
63 | \end{code}
64 |
65 | Now let us create a new tag and give it some extra information.
66 | \index{tagging!annotated}
67 | \begin{code}
68 | john@satsuki:~/coderepo$ git tag v1.0b -m 'This is an annotated tag'
69 | john@satsuki:~/coderepo$
70 | \end{code}
71 |
72 | Unfortunately Git was not particularly forthcoming with information on the creation of the tag.
73 | On saying that, it is not difficult for us to use the \texttt{git show} command to see what we have done.
74 |
75 | \begin{code}
76 | john@satsuki:~/coderepo$ git show v1.0b
77 | tag v1.0b
78 | Tagger: John Haskins
79 | Date: Thu Mar 31 23:55:50 2011 +0100
80 |
81 | This is an annotated tag
82 |
83 | commit a022d4d1edc69970b4e8b3fe1da3dccd943a55e4
84 | Author: John Haskins
85 | Date: Thu Mar 31 22:05:55 2011 +0100
86 |
87 | Messed with a few files
88 |
89 | diff --git a/my_second_committed_file b/my_second_committed_file
90 | index 095b9cd..c9887f8 100644
91 | --- a/my_second_committed_file
92 | +++ b/my_second_committed_file
93 | @@ -1,2 +1 @@
94 | -Change1
95 | -Change2
96 | +Changed this file completely
97 | diff --git a/my_third_committed_file b/my_third_committed_file
98 | new file mode 100644
99 | index 0000000..5d27866
100 | --- /dev/null
101 | +++ b/my_third_committed_file
102 | @@ -0,0 +1 @@
103 | +Addition to the line
104 | john@satsuki:~/coderepo$
105 | \end{code}
106 |
107 | Notice that as well as showing us the tag itself, the \texttt{git show} command also gave us a diff of what exactly changed in this commit.
108 | Small details like this are what makes Git in particular a joy to use for developers.
109 |
110 | If we found that we had actually created the tag incorrectly, we have two options, we could use the \texttt{-d} option to delete a tag, or we could use the \texttt{-F} option to forcibly overwrite a tag with the same name with different information.
111 | However please remember the warning about tags in \emph{Week 2}.
112 | It is very dangerous to go changing tags, especially if you have already pushed them out somewhere where other people can grab them from.
113 |
114 | Now that we have learnt a little about how to play with tags, we should probably take a look under the hood.
115 | This is an After Hours section after all.
116 |
117 | The implementation of tags in Git is very simple indeed.
118 | We are going to jump into the \texttt{.git} directory and take a look at a simple output from some commands.
119 |
120 | \begin{code}
121 | john@satsuki:~/coderepo$ cd .git/
122 | john@satsuki:~/coderepo/.git$ ls
123 | branches config HEAD index logs refs
124 | COMMIT_EDITMSG description hooks info objects
125 | john@satsuki:~/coderepo/.git$ cd refs/tags/
126 | john@satsuki:~/coderepo/.git/refs/tags$ ls
127 | v0.9 v1.0a v1.0b
128 | john@satsuki:~/coderepo/.git/refs/tags$ cat v1.0a
129 | a022d4d1edc69970b4e8b3fe1da3dccd943a55e4
130 | john@satsuki:~/coderepo/.git/refs/tags$
131 | \end{code}
132 |
133 | Inside the \texttt{.git/refs/tags} folder, there is a file for every single tag in the system.
134 | This file contains a single string of characters.
135 | That string looks oddly like an SHA-1 commit to me.
136 | Using the tricks that we learnt in the last After Hours section, we can interrogate the Git repository, by throwing a few wrenches at it.
137 |
138 | \begin{code}
139 | john@satsuki:~/coderepo$ git cat-file -p a022d4
140 | tree 96551f45496232c0ec6b389731d55fa3d7e1c8fd
141 | parent 9938a0c30940dccaeddce4bb2eb151fba3a21ae5
142 | author John Haskins 1301605555 +0100
143 | committer John Haskins 1301605555 +0100
144 |
145 | Messed with a few files
146 | john@satsuki:~/coderepo$ git cat-file -t a022d4
147 | commit
148 | john@satsuki:~/coderepo$
149 | \end{code}
150 |
151 | Excellent! Just as we expected.
152 | So Git stores the SHA-1 hash for the commit we are referring to, in a file which has the same name as the tag.
153 | Just for clarity, let us run the same set of commands against our newly created annotated tag.
154 |
155 | \begin{code}
156 | john@satsuki:~/coderepo$ cd .git/refs/tags/
157 | john@satsuki:~/coderepo/.git/refs/tags$ cat v1.0b
158 | 6cbcf47957589bf4b84cc934a26731636d021574
159 | john@satsuki:~/coderepo/.git/refs/tags$
160 | \end{code}
161 |
162 | Hang on a minute! Shouldn't the output of the \texttt{v1.0a} and \texttt{v1.0b} files be the same.
163 | There were both created at the same point in the repositories history.
164 | They were both supposed to be pointing to the same commit.
165 | Let us use a little plumbing and see what is going on.
166 |
167 | \begin{code}
168 | john@satsuki:~/coderepo$ git cat-file -t 6cbcf4
169 | tag
170 | john@satsuki:~/coderepo$
171 | \end{code}
172 |
173 | Interesting.
174 | So it seems as if there is another type of object that can be added to the list.
175 | The \emph{tag} object.
176 | So what exactly is the difference here? To answer that we need to take a look at the difference between the two tags.
177 | \texttt{v1.0a} was a simple tag, whereas \texttt{v1.0b} is an annotated tag.
178 |
179 | When the tag was merely a pointer to a commit object, the repository required nothing more that the object that it was referring to, to be stored in the file.
180 | Now we have more information, Git treats the information just as it would any other, by creating an object.
181 | We can investigate this further and use the \texttt{-p} parameter to the \texttt{git cat-file} command to see exactly what is stored within this file.
182 |
183 | \begin{code}
184 | john@satsuki:~/coderepo$ git cat-file -p 6cbcf4
185 | object a022d4d1edc69970b4e8b3fe1da3dccd943a55e4
186 | type commit
187 | tag v1.0b
188 | tagger John Haskins
189 | Thu Mar 31 23:55:50 2011 +0100
190 |
191 | This is an annotated tag
192 | john@satsuki:~/coderepo$
193 | \end{code}
194 |
195 | So an annotated tag contains more information than just the commit ID we are referring to.
196 | This is pretty handy and later on in the book we will start talking about topics like signed tags, which are required if you wish to verify the identity of the person claiming to have created the tag.
197 |
198 | A shorter After Hours section this time.
199 | Next time we will move on to taking a deeper look at what happens behind the scenes with branches and merging.
200 | Stay tuned.
201 |
--------------------------------------------------------------------------------
/afterhours4.tex:
--------------------------------------------------------------------------------
1 | % afterhours4.tex - Afer Hours Week 4
2 | \chapter{After Hours Week 4}
3 | \section{``Merge merge merge''}
4 | \subsection{How does merging work?}
5 | To start with, we need to define which merging strategy we are talking about.
6 | In Git there are multiple ways to instruct a merge to take place.
7 | Below is a brief list of the options that you can supply to the \texttt{git merge} command along with a brief description of how each one affects the merge process.
8 | We will explain the details a little more further on.
9 | \index{merging!types}\index{merging!types!resolve}\index{merging!types!recursive}\index{merging!types!octopus}\index{merging!types!ours}\index{merging!types!subtree}
10 |
11 | \begin{itemize}
12 | \item\textbf{Resolve} - A two headed merge strategy using a 3-way merge algorithm.
13 | This is used by default in Git.
14 | \item\textbf{Recursive} - A two headed merge strategy using a 3-way merge algorithm.
15 | This algorithm looks at situations where multiple common ancestors are eligible and creates a merged tree of the common ancestors to be used as a reference.
16 | Usually, this method has less conflicts and carries with it multiple sub-options.
17 | \item\textbf{Octopus} - This merge strategy can merge in multiple heads.
18 | When trying to pull multiple topic branches into a single merge, an \textbf{octopus} is the default method that Git will use.
19 | \item\textbf{Ours} - Another multiple head strategy, which simply ignores all changes from the other branches.
20 | At first it may sound like a useless idea, but it could be used to keep the history of a branch without actually keeping the branch itself.
21 | \item\textbf{Subtree} - A much more advanced merge strategy based on the \textbf{recursive} which trees are adjusted to result in a better merge.
22 | \end{itemize}
23 |
24 | Now that we are aware of the different options available to us, let us discuss what happens when we actually perform a merge.
25 | Let us consider the state of our repository at the end of Week 4, as shown in Figure 1.
26 |
27 | \figuregith{9cm}{images/f-w4-d6.pdf}{Repository at the end of \emph{Week 4}}
28 |
29 | For arguments sake, let us say that we were on the \textbf{wonderful} branch, and we wanted to merge the \textbf{zaney} branch into it.
30 | Using a standard 3-way merge algorithm, this would mean taking our current branch, which we will call \textbf{A}, the \textbf{zaney} branch, which we will call \textbf{B} and a parent which we will \textbf{C}.
31 | Why do we need this parent? What is it used for?
32 |
33 | \index{Best Common Ancestor}In order to merge changes from a specific file together, we need to know exactly how that file has changed over time.
34 | In order to know that, we need to have a common starting point.
35 | By that we mean that we need to have a state in both of the branches history, where \textbf{A} and \textbf{B} were the same.
36 | In a version control system, this is most easily achieved by finding a commit that is common to the history of both branches.
37 | This commit is called the \emph{Best Common Ancestor}.
38 |
39 | Usually, when developing software, the code tree will be branched at various points along the way.
40 | Sometimes we may need to merge these branches together, or merge these branches back into the master branch.
41 | Which ever way we do it, we will need to find a common ancestor.
42 | Figure 2, demonstrates a couple of possible merge proposals, and one of their common ancestors.
43 |
44 | \figuregith{6cm}{images/f-af4-d2.pdf}{Finding the \emph{Best Common Ancestor}}
45 |
46 | \index{Common Ancestor}As you can see from the second example, branch \textbf{B} was created from a commit above the \emph{Common Ancestor}, but the \emph{Common Ancestor} remains the same.
47 |
48 | Let us go back to our example above.
49 | We are attempting to merge in \textbf{zaney} to the \textbf{wonderful} branch.
50 | We need to find the \textbf{C} in our equation.
51 | To do this we could pour over Figure 1.
52 | This should yield the result to be commit \textbf{9710177}.
53 | Is there any way we can ask Git to do the same thing? The following output introduces a new command that is used to find the \emph{Best Common Ancestor} for a given merge proposal.
54 |
55 | \begin{code}
56 | john@satsuki:~/coderepo$ git merge-base wonderful zaney
57 | 9710177657ae00665ca8f8027b17314346a5b1c4
58 | john@satsuki:~/coderepo$ git cat-file -p 9710177
59 | tree 268f487e5c29a4b01c3a91637bac0024253fb77e
60 | parent 55fb69f4ad26fdb6b90ac6f43431be40779962dd
61 | author John Haskins 1301613377 +0100
62 | committer John Haskins 1301613377
63 | +0100
64 |
65 | Added another file
66 | john@satsuki:~/coderepo$
67 | \end{code}
68 |
69 | In our example, \indexgit{merge-base} uses two parameters to speficy the two heads that we wish to merge.
70 | We can see that the commit that Git suggests as the \emph{Best Common Ancestor} is what we suggested above, \textbf{9710177}.
71 | We have reused our \texttt{git cat-file} command to prove that the commit is the one we suggested, as you can see, the commit messages match.
72 |
73 | This explains how a simple merge takes place, Git will find the common ancestor, and try to merge in the differences to produce a merged version.
74 | If the merge cannot take place, then as shown in \emph{Week 4}, Git will put all the changes in the file, label them, and then raise a conflict for the user to resolve.
75 |
76 | With the information presented here, you should now be able to reread the descriptions above and understand what is going on at a base level.
77 | If you require further information on merging, there is a wealth of documentation and papers about merge algorithms on the Internet.
78 |
79 | \section{``Grepping your life away''}
80 | \subsection{A subtle twist on searching}
81 | As well as our \texttt{git log} tool, which we have used for searching, it is useful to know that there is actually another way to search for strings in your current directory.
82 | We can use the \indexgit{grep} tool to find all files in our working tree which have a certain pattern in them.
83 |
84 | \begin{code}
85 | john@satsuki:~/coderepo$ git grep awesome
86 | newfile1:and some more awesome changes
87 | newfile2:and a new awesome feature
88 | john@satsuki:~/coderepo$
89 | \end{code}
90 |
91 | This has returned two files, both containing the string \texttt{awesome}, as this is the parameter that we passed to the \texttt{git grep} command.
92 |
93 | We can extend this a little further and ask Git to supply the context around the line that it finds.
94 | In our simple case, it results in the following.
95 |
96 | \begin{code}
97 | john@satsuki:~/coderepo$ git grep -C3 awesome
98 | newfile1-A new file
99 | newfile1:and some more awesome changes
100 | --
101 | newfile2-Another new file
102 | newfile2:and a new awesome feature
103 | john@satsuki:~/coderepo$
104 | \end{code}
105 |
106 | This is just a short introduction to the \texttt{git grep} command.
107 | If you want to know more you should spend some time reading the manual.
108 |
--------------------------------------------------------------------------------
/afterhours6.tex:
--------------------------------------------------------------------------------
1 | % afterhours6.tex - Afer Hours Week 6
2 | % Still need to fix nested lists :(
3 | \chapter{After Hours Week 6}
4 | \section{``Tug of war''}
5 | \subsection{Taking the push with the pull}
6 | We have spoken at fairly great length about how remote repositories work.
7 | We have seen how the \texttt{git remote} tool is used to create the various references to remote repositories, but we have no real understanding about what this means in terms of Git's internals.
8 | Just in the same way a branch is a single file that contains a pointer to a reference, a remote repository has to be handled within Git somehow.
9 |
10 | As it happens, Git again uses a reasonably simplistic design when creating \index{remote references}remote references.
11 | To take a look at this in detail, we need to once again delve into the \texttt{.git} directory.
12 | Seeing as our original repository does not contain any remotes for now, we are going to use our \texttt{coderepo-cl} folder as an example.
13 | Hopefully, if you have been following the text, you have not deleted this directory yet.
14 | If you have, do not worry, just follow the operations we completed in Week 6, or read on and use the text in the book.
15 |
16 | If you remember, we created two clones of our original repository.
17 | One of these was a simple clone called \texttt{coderepo-cl} and the other was a bare repository called \texttt{coderepo-bk}.
18 | The \texttt{coderepo-cl} and the \texttt{coderepo-bk} repositories were both cloned from \texttt{coderepo}, but it was \texttt{coderepo-cl} that was configured to pull from one and push to the other.
19 | Running a simple \texttt{git remote -v} command, confirms this configuration.
20 |
21 | \begin{code}
22 | john@satsuki:~/coderepo-cl$ git remote -v
23 | backup /home/john/coderepo-bk (fetch)
24 | backup /home/john/coderepo-bk (push)
25 | origin /home/john/coderepo (fetch)
26 | origin /home/john/coderepo (push)
27 | john@satsuki:~/coderepo-cl$
28 | \end{code}
29 |
30 | We can get even more information by running the \texttt{git remote show} tool with the remote name as a parameter.
31 |
32 | \begin{code}
33 | john@satsuki:~/coderepo-cl$ git remote show origin
34 | * remote origin
35 | Fetch URL: /home/john/coderepo
36 | Push URL: /home/john/coderepo
37 | HEAD branch: master
38 | Remote branches:
39 | master tracked
40 | wonderful tracked
41 | zaney tracked
42 | Local branches configured for 'git pull':
43 | master merges with remote master
44 | wonderful merges with remote wonderful
45 | Local refs configured for 'git push':
46 | master pushes to master (up to date)
47 | wonderful pushes to wonderful (up to date)
48 | john@satsuki:~/coderepo-cl$
49 | \end{code}
50 |
51 | How though, is this data set up and configured from within Git itself?
52 | Looking at the \texttt{.git/config} file, we can see a glimpse of this.
53 |
54 | \begin{code}
55 | john@satsuki:~/coderepo-cl$ cat .git/config
56 | [core]
57 | repositoryformatversion = 0
58 | filemode = true
59 | bare = false
60 | logallrefupdates = true
61 | [remote "origin"]
62 | fetch = +refs/heads/*:refs/remotes/origin/*
63 | url = /home/john/coderepo
64 | [branch "master"]
65 | remote = origin
66 | merge = refs/heads/master
67 | [branch "wonderful"]
68 | remote = origin
69 | merge = refs/heads/wonderful
70 | [remote "backup"]
71 | url = /home/john/coderepo-bk
72 | fetch = +refs/heads/*:refs/remotes/backup/*
73 | john@satsuki:~/coderepo-cl$
74 | \end{code}
75 |
76 | As you can see there are two relevant sections, these are the \texttt{remote} and \texttt{branch} stanzas.
77 | The \texttt{remote} stanzas are there to define certain elements of the remote repository,
78 | whilst the \texttt{branch} stanzas describe elements and settings for the branches that we are tracking.
79 | Let us look at the relevant elements that we have set out in \texttt{config} file for each type of stanza.
80 |
81 | We will start by looking at the \texttt{remote} \index{stanza}stanza. We have two settings here in our configuration.
82 | The first is \texttt{url} and the second is \texttt{fetch}.
83 | \index{settings!url}The \texttt{url} setting tells Git the location of the remote repository defined by the name outlined within the quotation marks.
84 | In our example, the remote we first encounter is called \textbf{origin} and has a url of \texttt{/home/john/coderepo}.
85 |
86 | \index{settings!fetch}You will notice that there is also a second setting called \texttt{fetch}.
87 | This setting tells Git which branches, or HEADs we are interested in. In the default configuration, we ask Git to fetch all branch HEADs.
88 | This also has an effect on which objects are downloaded.
89 | Git will look at all of the branch HEADs and work backwards to find out which commit objects need to be downloaded.
90 |
91 | In the \texttt{refs/} folder there are two other folders by default called \texttt{tags} and \texttt{remotes}.
92 | With the default configuration as above, these references will not be fetched,
93 | and commits that are only pointed to by these references will not be downloaded either.
94 |
95 | \index{settings!branch}Looking at the \texttt{branch} settings, we can see that there are a few more settings here that describe how Git responds to certain commands when inside a certain branch.
96 | In both the cases above, Git will automatically use remote of \textbf{origin} as the remote to use when performing operations.
97 | This means that when we run a \texttt{git pull}, we do not have to specify a remote to pull from.
98 | Obviously if we wanted to, we could change this and have \textbf{wonderful}, for example, update from a different remote repository.
99 |
100 | \index{settings!merge}The last setting in this file that we will concern ourselves with is the \texttt{merge} setting.
101 | When we are in the named branch, this setting defines the upstream version of the named branch and is used for merging and can affect pulling and rebasing too.
102 |
103 | We can set these settings and any of the others in the \texttt{config} file manually,
104 | using the \texttt{git config} tool, which we used in a previous chapter.
105 |
106 | \section{``Referring to objects''}
107 | \subsection{The Git spelling bee}
108 | It is now most definitely time we spoke about other ways to represent commit hashes.
109 | More details can be found about this in the Git manual, but it is definitely worth spending a few minutes looking at the ways in which we can specify objects in the repository.
110 | As you have seen in previous chapters, we have used branch names, commits hashes and tags to specify commits, but it is also possibly to use a variety of other methods to do so.
111 | We are going to use the \indexgit{rev-parse} command again to return us an object hash from our description of an object.
112 | These descriptions are ways to \emph{spell} objects.
113 |
114 | \begin{itemize}
115 | \item\index{sha1}\texttt{} - This is most common way to specify an object.
116 | The \texttt{} is the 40 character identifier that Git generates for each object.
117 | As you have seen before, we do not have to specify the entire SHA1 hash, just the beginning portion that is unique.
118 | \item\index{refname}\texttt{} - We use this type of referencing a lot when checking out branches.
119 | The \texttt{} is a symbolic name.
120 | An example of this would be \textbf{master}, which actually refers to \textbf{refs/heads/master}, which you have seen in the \texttt{.git} directory.
121 | HEAD is also a \texttt{}. In general, Git will search through a number of directories to find the \texttt{} that is being referred to;
122 | \begin{itemize}
123 | \item \texttt{.git/}
124 | \item \texttt{refs/}
125 | \item \texttt{refs/tags/}
126 | \item \texttt{refs/heads/}
127 | \item \texttt{refs/remotes/}
128 | \item \texttt{refs/remotes//HEAD}
129 | \end{itemize}
130 | So if we used \textbf{master} as our \texttt{}, Git would search in \texttt{.git} root directory first,
131 | then into \texttt{refs}, followed by \texttt{refs/tags}, and finishing with \texttt{refs/heads}.
132 | \item\index{date}\texttt{@\{date\}} - Now we find a more interesting way of specifying references.
133 | We can use something like \textbf{master@\{yesterday\}}, to show us the closeset commit to match that date time.
134 | There are more complicated date specifications we can use as well, such as \textbf{master@\{"last week"\}}, or \textbf{master@\{"3 hours 2 minutes and 10 seconds ago"\}}.
135 | We can even put in a specific date and time like so; \textbf{master@\{"2011-02-26 14:30:00"\}}
136 | \item\texttt{@\{\}} - This curious definition returns the commit that \texttt{} referred to \texttt{} times in the past.
137 | It uses the \emph{reflog}, which has been discussed before, to discover what commit \texttt{} pointed to.
138 | Be careful when using this reference. It does not mean the commit that \texttt{} pointed \texttt{} commits ago in the tree.
139 | If you have been doing resets and other things, these items show up in the \emph{reflog}.
140 | \item\texttt{\textasciicircum} - Is a way of asking Git to traverse an object for it's parents and so \texttt{} or \texttt{\textasciicircum 1} means the first parent of a commit object.
141 | An example of this would be \texttt{master\textasciicircum2}.
142 | \item\texttt{\textasciitilde} - Is a way of asking Git to traverse an object for it's \texttt{}th grand-parent, following only first parents.
143 | This will take a little understanding and it is advised that you read the man page online for more information about what this really means.
144 | \item\texttt{\textasciicircum\{/\}} - This definition actually initiates a search for the youngest commit where the commit message matches the regular expression after the slash.
145 | \texttt{master\textasciicircum\{/bug\}} is an example of the usage of this reference definition.
146 | \item\texttt{:} - This allows us to obtain the object hash for the file specified at the \texttt{}.
147 | We could then use the \texttt{git show} command to view that file.
148 | As an example \texttt{git show HEAD\textasciitilde 3:readme.txt} would show us the file \texttt{readme.txt} as it was three grandparents back from HEAD.
149 | \end{itemize}
150 |
151 | All of these are valid ways to refer to commits and in some cases objects and trees too.
152 | Imagine a situation where you wanted to view a file called \texttt{readme.txt} that was three commits back from a tag of \texttt{v44}.
153 | Using our new knowledge, we could use \texttt{git show v44\textasciitilde 3:readme.txt}.
154 | There are several other ways of referring to commits, but these are out of the scope of this chapter.
155 | If you would like more information, refer to the man page for \texttt{git rev-parse}.
156 |
--------------------------------------------------------------------------------
/afterhours7.tex:
--------------------------------------------------------------------------------
1 | % afterhours7.tex - Afer Hours Week 7
2 | \chapter{After Hours Week 7}
3 | \section{``Network Communicating''}
4 | The last week began by looking at some networking communication.
5 | In the After Hours section this week, we are going to look at two tools which are used for network communication.
6 |
7 | \subsection{Brewing a website - in an instant}
8 | The \emph{Instaweb} tool allows you to spawn a web service quickly and easily, using a web daemon of your choice.
9 | The \emph{Instaweb} tool actually uses \texttt{gitweb} which is a more permanent solution for obtaining the same functionality as \emph{Instaweb}.
10 | If you have never played with web services before it would be worth spending a few minutes understanding a little about how web daemons work.
11 | This tool is not available on the Windows platform, but it can be used on both MacOS and Linux.
12 |
13 | \emph{Instaweb} allows us to browse our repository from the comfort of a web browser.
14 | We also have another benefit to running this from a web server.
15 | We can allow people to access our repository to look around without giving them the ability to change anything or make any commits.
16 |
17 | Before we run \texttt{git instaweb}, we need to ensure that we have a web daemon available to us.
18 | \emph{Instaweb} automatically creates a configuration file for the web daemon of your choice, runs the daemon on a custom network port,
19 | and loads a browser automatically pointing to the URL of the web instance you have just configured.
20 | On our example machine, we have installed \index{lighttpd}lighttpd as our choice of web daemon.
21 | Once again it is advised to understand the implications of this before you do it.
22 | On Ubuntu, this can be installed by running \texttt{apt-get install lighttpd}.
23 |
24 | \begin{code}
25 | john@satsuki:~/coderepo$ git instaweb
26 | john@satsuki:~/coderepo$
27 | \end{code}
28 |
29 | The tool is invoked by running \texttt{git instaweb} and when started, you should be presented with a browser as pictured below.
30 | In our case, lighttpd has been installed, and so Git will use that as its daemon.
31 | Firefox is also the default browser on this machine and so this is the browser that Git will choose to display the web page in.
32 | If we wanted to use an alternative browser, we could have supplied an argument with \texttt{--browser}, like \texttt{--browser chromium} for example.
33 |
34 | \figuregith{12cm}{images/f-af7-d1.png}{Instaweb's default page}
35 |
36 | The first thing to notice is that the description of the repository is unhelpful.
37 | In Figure 1, it is shown as \texttt{Unnamed repository; edit this...}.
38 | It is easy to rectify this, by editing the \texttt{.git/description} file.
39 | We are going to use the \texttt{echo} command from Linux, as we have throughout the book.
40 |
41 | \begin{code}
42 | john@satsuki:~/coderepo$ echo "Our test repository" > .git/description
43 | john@satsuki:~/coderepo$
44 | \end{code}
45 |
46 | On refreshing the page, the description will be updated.
47 | The next thing to notice is the url.
48 | The screenshot shows our url to be \texttt{http://127.0.0.1:1234/}, where \texttt{127.0.0.1} is the local address of our Git machine and \texttt{1234} is the port.
49 |
50 | Before we start taking a look around the web interface, we should learn how to end the \emph{Instaweb} session.
51 | If we close the web browser, it does not end the \emph{Instaweb} process.
52 | In fact, we could load up firefox again, type in the URL \texttt{http://127.0.0.1:1234/} and return to the home page of our Git repository.
53 | To close the instance of \emph{Instaweb} we run the following;
54 |
55 | \begin{code}
56 | john@satsuki:~/coderepo$ git instaweb --stop
57 | john@satsuki:~/coderepo$
58 | \end{code}
59 |
60 | Now would be a good time to take a quick look at what running \texttt{git instaweb} has done to our repository.
61 | If we take a look inside the \texttt{.git} folder, we can see that there is a new folder called \texttt{gitweb}.
62 | This folder contains configuration and log files for the \emph{Instaweb} process.
63 | The file we are most interested in is \texttt{httpd.conf}.
64 | Looking at the beginning of this file we should see something similar to the following.
65 |
66 | \begin{code}
67 | server.document-root = "/usr/share/gitweb"
68 | server.port = 1234
69 | server.modules = ( "mod_setenv", "mod_cgi" )
70 | server.indexfiles = ( "gitweb.cgi" )
71 | server.pid-file = "/home/john/coderepo/.git/pid"
72 | server.errorlog = "/home/john/coderepo/.git/gitweb/lighttpd/error.log"
73 | \end{code}
74 |
75 | Here we can see the beginning of the config file that Git has created for using with lighttpd.
76 | If we had other web daemons installed, such as apache, we could override the default of lighttpd by supplying the \texttt{--httpd apache2}.
77 | Notice the port number which as been defined as \texttt{1234}.
78 | Let us run up \texttt{git instaweb} again and see what other features the web interface offers.
79 |
80 | \figuregith{12cm}{images/f-af7-d2.png}{Instaweb's repository page (top)}
81 |
82 | \figuregith{12cm}{images/f-af7-d3.png}{Instaweb's repository page (bottom)}
83 |
84 | Figures 2 and 3 show how the web interface looks when browsing our repository.
85 | At the top of the page we see a history of commits along with a search box which works similar to the \texttt{gitk} system which was discussed earlier.
86 | At the bottom of the page, we see our \textbf{tags} and \textbf{heads}.
87 | There are several link names which we will briefly describe now.
88 |
89 | \begin{itemize}
90 | \item \index{gitweb!shortlog}\textbf{shortlog} - Gives a log of the commits, similar to that shown in Figure 2.
91 | \item \index{gitweb!commit}\textbf{commit} - Returns a page that gives details about a specific commit.
92 | The \textbf{commit} page is shown in Figure 4.
93 | \item \index{gitweb!commitdiff}\textbf{commitdiff} - Shows how the chosen diff has changed since its parent.
94 | This is similar to running our \texttt{git diff HEAD~1..HEAD} command.
95 | \item \index{gitweb!tree}\textbf{tree} - This page is a simple listing of the tree object which shows all files present in that particular commit.
96 | \item \index{gitweb!snapshot}\textbf{snapshot} - Possibly one of the most useful links.
97 | Clicking on this will initiate a download of the repositories filesystem at that particular point in time.
98 | \item \index{gitweb!log}\textbf{log} - Gives a listing of the full log messages.
99 | \end{itemize}
100 |
101 | Let us take a little look around the interface.
102 | Choosing the first commit in the list on the homepage and clicking on the \textbf{commit} link moves on to the commit page.
103 | Here we can see detailed information about the commit.
104 |
105 | \figuregith{12cm}{images/f-af7-d4.png}{Instaweb's default page}
106 |
107 | The \textbf{commit}, \textbf{tree} and \textbf{parent} object hashes are displayed here for reference.
108 | The \textbf{tree} and \textbf{parent} lines are clickable links which will take us to those relevant sections.
109 | We are going to choose the \textbf{tree} link.
110 | A screenshot of the resulting page is shown in Figure 5.
111 |
112 | \figuregith{12cm}{images/f-af7-d5.png}{Instaweb's default page}
113 |
114 | Going back and clicking on the snapshot link will initiate a download of the entire filesystem, at that point in the repository's life.
115 | As shown in Figure 6.
116 |
117 | \figuregith{10cm}{images/f-af7-d6.png}{Instaweb's default page}
118 |
119 | This has been a very brief tour around the \texttt{gitweb} system.
120 | Hopefully you can see that this is a very useful tool to add to our Git suite.
121 | If you are considering setting up a permanent web based view for your Git repository, you should not use \emph{Instaweb}.
122 | This tool is intended for quick and easy web access to a repository.
123 | There are plenty of guides and tutorials available which explain the installation and configuration of \texttt{gitweb}.
124 |
125 | \subsection{Pushing and pulling with a daemon}
126 | The \texttt{git instaweb} daemon is very useful indeed.
127 | However, one function that it does not provide is the ability to clone or fetch from the URL.
128 | Another tool which comes with the Git package is the \indexgit{daemon} utility and it is this tool which is going to give us this functionality.
129 | We spoke earlier about the GIT protocol and it just so happens that \texttt{git daemon} uses the GIT protocol for transferring data.
130 | Let us have a look at a simple example of using \texttt{git daemon}.
131 |
132 | \begin{code}
133 | john@satsuki:~$ git daemon --base-path=/home/john/coderepo
134 | \end{code}
135 |
136 | Notice how this command has not exited.
137 | This is because the process is still running, waiting for communication.
138 | We can now log into another machine on the same network and clone the repository using our \texttt{git clone} command.
139 | We will supply the host name of the machine that we configured with \texttt{git daemon}, and a directory for us to clone into.
140 | Notice the presence of \texttt{git://} instead of \texttt{ssh://} as we used in our previous network cloning example.
141 |
142 | \begin{code}
143 | rob@mimi:~$ cd /tmp
144 | rob@mimi:/tmp$ mkdir source
145 | rob@mimi:/tmp$ git clone git://satsuki/ source
146 | Cloning into source...
147 | fatal: The remote end hung up unexpectedly
148 | rob@mimi:/tmp$
149 | \end{code}
150 |
151 | That did not go as expected and resulted in a failed clone.
152 | If we look back at the source machine we can see something interesteing has appeared.
153 |
154 | \begin{code}
155 | john@satsuki:~$ git daemon --base-path=/home/john/coderepo
156 | [4687] '/home/john/coderepo/.git': repository not exported.
157 | john@satsuki:~$
158 | \end{code}
159 |
160 | This is probably one of the most common of all errors when dealing with \texttt{git daemon}.
161 | By default, Git tries to protect your repositories and will not allow them to be exported unless you explicitly tell it to.
162 | We have two ways of doing this.
163 | We can append the \texttt{--export-all} parameter to \texttt{git daemon}, which will allow exporting of all repositories which are under the path described in \texttt{--base-path}.
164 | The second method is to explicitly tell Git on a repository by repository, that we would like for it to be exported, or more accurately that we would like to opportunity to export it.
165 | We are going to do the latter of the two and we do this by creating a special file in the \texttt{.git} directory, called \texttt{git-daemon-export-ok}.
166 |
167 | To add this file, we are going to need to stop the daemon by pressing the \textbf{ctrl+c} key combination.
168 | Then we ran run the commands as shown below.
169 |
170 | \begin{code}
171 | john@satsuki:~$ touch coderepo/.git/git-daemon-export-ok
172 | john@satsuki:~$ git daemon --base-path=/home/john/coderepo
173 |
174 | \end{code}
175 |
176 | Now we can go back to our second machine again and try to clone the repository as before.
177 |
178 | \begin{code}
179 | rob@mimi:/tmp$ git clone git://satsuki/ source
180 | Cloning into source...
181 | remote: Counting objects: 71, done.
182 | remote: Compressing objects: 100% (51/51), done.
183 | remote: Total 71 (delta 16), reused 0 (delta 0)
184 | Receiving objects: 100% (71/71), 6.47 KiB, done.
185 | Resolving deltas: 100% (16/16), done.
186 | rob@mimi:/tmp$
187 | \end{code}
188 |
189 | Et voila! Our repository has been cloned.
190 | As we exported the root of our repository using the \texttt{--base-path} parameter, we do not need to specify to the clone command which repository we are trying to clone.
191 | If you remember we did have some other repositories in the home folder and if we had exported \texttt{/home/john/}, instead of \texttt{/home/john/coderepo},
192 | then we could have chosen any of the repositories that lay in the home folder by appending their names to the URL.
193 | An example of this would be \texttt{git://satsuki/coderepo/} or \texttt{git://satsuki/coderepo-cl/}.
194 |
195 | By default the \texttt{git daemon} tool only allows people to fetch objects from the repository.
196 | This is quite sensible because as you can see there is no authentication present with the GIT protocol at all.
197 | You \emph{can} enable pushing of objects to your repository using the GIT protocol, but this is only advised within a well trusted LAN environment.
198 | Otherwise you are giving whoever else is on your network the capability to push whatever they want into your repository, which as you can understand is not a good idea.
199 |
200 | We can run the daemon tool in the background by supplying the \texttt{--detach} parameter.
201 | However if you are unfamiliar to the Linux world, this requires some knowledge to stop the daemon again.
202 | Running the daemon detached will result in your shell returning to the prompt, seemingly not have executed anything.
203 | In fact the process has been moved to the background and no longer supports shell interaction.
204 | The benefit of this is that you do not have to keep a shell window open to run it in.
205 | The downside is that you can no longer end the process with the \textbf{ctrl+c} key combination.
206 |
207 | You can hopefully see that by using the \texttt{git daemon} tool, it is possible for us to allow other people on our network to have access to our repositories.
208 | Whilst the \texttt{git daemon} tool is very useful, it does have its disadvantages as stated, primarily in areas of version control.
209 | However, seeing how efficient the GIT protocol is compared to its other counterparts, it often makes a fantastic device for making a repoitory available to pull from.
210 |
211 | There are much more complicated configurations that can be performed with the daemon tool, but these are out of the scope of this chapter.
212 | The manual page for \texttt{git daemon} has some examples to get you started,
213 | and even goes into the areas of virtual hosting to allow multiple Git \emph{sites} to exist on one server.
214 |
--------------------------------------------------------------------------------
/afterhours8.tex:
--------------------------------------------------------------------------------
1 | % afterhours8.tex - Afer Hours Week 8
2 | \chapter{After Hours Week 8}
3 | \section{``Fishing for beginners''}
4 | \subsection{Hooking your scripts up}
5 | So we come to the last After Hours section of the book and this time we are going to take a look at hook scripts.
6 | Hook scripts are tiny pieces of code that you are allowed to have executed at certain points during Git's processes which can affect the outcome of those same processes.
7 | Imagine for example that whenever you committed to a repository you wanted an email to be sent to the project manager.
8 | That is a job for a hook script.
9 |
10 | The are a fairly large number of hook points available.
11 | They are called hooks because it allows you to hook something else into the Git process.
12 | Below is a list of a few of the available hook points along with a very brief description of when they are triggered and how they can affect the process.
13 | For a full list, you should check out the manual for githooks.
14 |
15 | \begin{itemize}
16 | \item\textbf{applypatch-msg} - Invoked by \texttt{git am}, it is provided with the name of the proposed commit message for the patch and allows for sanitisation.
17 | Exiting with a non-zero status will cause \texttt{git am} to abort the patch.
18 | Will run the \textbf{commit-msg} hook if enabled.
19 | \item\textbf{pre-applypatch} - Invoked by \texttt{git am}, it runs immediately after the patch is applied, but before a commit is made.
20 | In this way, checks can be made to the working tree before committing.
21 | Exiting with non-zero status aborts the commit.
22 | Will run the \textbf{pre-commit} hook if enabled.
23 | \item\textbf{post-applypatch} - Invoked by \texttt{git am}, it runs after the patch is applied and the commit is made.
24 | It does not affect the flow of \texttt{git am} and as such is useful for actions such as notifications.
25 | \item\textbf{pre-commit} - This hook is invoked by \texttt{git commit} and can be bypassed with the \texttt{--no-verify} option.
26 | Exiting with non-zero status aborts the commit.
27 | \item\textbf{prepare-commit-msg} - This hook is invoked by \texttt{git commit} and is run immediately after the commit message has been prepared, but before the message editor has been loaded.
28 | It takes three parameters, the file containing the log message, the source of the commit message and an SHA hash.
29 | Exiting with non-zero status aborts the commit.
30 | It should not be used to replace \textbf{pre-commit}.
31 | \item\textbf{commit-msg} - This hook is invoked by \texttt{git commit} and can be bypassed with the \texttt{--no-verify} option.
32 | The hook is used to normalise messages in place before commit.
33 | Exiting with non-zero status aborts the commit.
34 | \item\textbf{post-commit} - Invoked by \texttt{git commit}, it runs immediately after a commit is made.
35 | It can not affect the flow of \texttt{git commit} and as such is useful for actions such as notifications.
36 | \item\textbf{pre-rebase} - Invoked by \texttt{git rebase}, it is useful for preventing a branch from being rebased.
37 | \item\textbf{post-checkout} - Invoked by \texttt{git checkout} after it has updated the working tree.
38 | The hook is given the ref of the previous HEAD, the new HEAD and a flag indicating if it was a branch or file checkout.
39 | It is also invoked after \texttt{git clone}, but can be overidden by the use of \texttt{--no-checkout}.
40 | The script is most useful for performing sanity and validity checks on the working tree post checkout.
41 | It does not affect the process of \texttt{git clone} or \texttt{git checkout}
42 | \item\textbf{post-merge} - Invoked by \texttt{git merge} when run as part of a \texttt{git pull}.
43 | It does not affect the outcome of the merge, but does not get executed if the merge fails due to conflicts.
44 | \end{itemize}
45 |
46 | So we have a large arsenal of hooks that we can employ to assist us in administrating our repository.
47 | We are going to set up a fairly simple example here of ensuring that we do not delete one of our core files.
48 | To begin with, let us add a \texttt{corefile} to the repository in a new branch and play a little with a new hook script.
49 |
50 | \begin{code}
51 | john@satsuki:~/coderepo$ git checkout -b hooktest
52 | Switched to a new branch 'hooktest'
53 | john@satsuki:~/coderepo$ echo "Very Important File" > corefile
54 | john@satsuki:~/coderepo$ git add corefile
55 | john@satsuki:~/coderepo$ git commit -a -m 'Added Core File'
56 | [hooktest 96fe8b9] Added Core File
57 | 1 files changed, 1 insertions(+), 0 deletions(-)
58 | create mode 100644 corefile
59 | john@satsuki:~/coderepo$
60 | \end{code}
61 |
62 | Now let us create a hook script called \texttt{.git/hooks/pre-commit}, with the following code.
63 |
64 | \begin{code}
65 | #!/bin/bash
66 |
67 | if [ -e "corefile" ]
68 | then
69 | echo "File OK"
70 | exit 0
71 | else
72 | echo "File Deleted Not Committing"
73 | exit 2
74 | fi
75 | \end{code}
76 |
77 | Now let us see what happens if we make a commit that does not affect the \texttt{corefile}.
78 |
79 | \begin{code}
80 | john@satsuki:~/coderepo$ echo "New Development" >> cont_dev
81 | john@satsuki:~/coderepo$ git commit -a -m 'Added a commit'
82 | File OK
83 | [hooktest 73656f2] Added a commit
84 | 1 files changed, 1 insertions(+), 0 deletions(-)
85 | john@satsuki:~/coderepo$
86 | \end{code}
87 |
88 | We see the text \texttt{File OK} in the output, which indicates that the commit is allowed to go ahead.
89 | What happens if we try to remove the core file and commit the result?
90 |
91 | \begin{code}
92 | john@satsuki:~/coderepo$ git rm corefile
93 | rm 'corefile'
94 | john@satsuki:~/coderepo$ git commit -a -m 'Removed a corefile'
95 | File Deleted Not Committing
96 | john@satsuki:~/coderepo$
97 | \end{code}
98 |
99 | We have been prevented from committing because we removed the all important \texttt{corefile}.
100 | To be able to commit again, we must return the file.
101 |
102 | \begin{code}
103 | john@satsuki:~/coderepo$ git checkout HEAD -- corefile
104 | john@satsuki:~/coderepo$ ls
105 | another_file cont_dev corefile tester
106 | john@satsuki:~/coderepo$ echo "New development" >> cont_dev
107 | john@satsuki:~/coderepo$ git commit -a -m 'Some more development'
108 | File OK
109 | [hooktest 6786dd5] Some more development
110 | 1 files changed, 1 insertions(+), 0 deletions(-)
111 | john@satsuki:~/coderepo$
112 | \end{code}
113 |
114 | So you see hooks can be really simple, or they can do highly complex things.
115 | Imagine a hook that would compile the code in the working tree prior to the commit and only allow it to continue if the code compiled cleanly.
116 | That could be pretty useful in ensuring that there is always good clean buildable code in the repository.
117 |
--------------------------------------------------------------------------------
/builder.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | make print
4 | cp gitt.pdf ../tempo/print.pdf
5 | make screen
6 | cp gitt.pdf ../tempo/screen.pdf
7 | make mobi
8 | cp build/complete.mobi ../tempo/
9 | make epub
10 | cp build/complete.epub ../tempo/
11 | make site
12 |
--------------------------------------------------------------------------------
/chap9.tex:
--------------------------------------------------------------------------------
1 | % chap9.tex - Week 9
2 | \cleardoublepage
3 | %\phantomsection
4 | \chapter{A little extra help}
5 | \section{Taking things further}
6 | We have completed our journey through eight weeks of intensive version control usage at Tamagoyaki Inc.
7 | However, there are probably still many questions that you have regarding Git and its usage.
8 | This chapter focusses on taking a few of the topics that were discussed a little further but does not go into as much detail as was presented in the rest of the book.
9 | The reason for this is purely that as the tasks you are trying to achieve become more complex, they often require greater knowledge about the implementation details
10 | and are often heavily customised to fit a particular scenario.
11 | Also, some of the topics are rather specialised and are not of use to everybody, so taking a large amount of time discussing them may be a little redundant for the majority of the people reading the book.
12 |
13 | If you have read through weeks 1-8, and supplemented it with the After Hours sections, you should have a very good understanding of the Git system.
14 | As with most things practice makes perfect and it is important to play with any new system before using it in earnest.
15 | If you are planning to migrate away from an existing version control system, take some time to test your current processes and procedures in Git to ensure that it will fit your needs.
16 | Always keep in mind that no matter which system you try to introduce, there will nearly always be resistance from someone.
17 |
18 | So let us touch on a few more topics and just wrap up a few loose ends.
19 |
20 | \subsection{Collaborating with a larger audience}
21 | We looked at a few tools within the Git system to allow access to a Git repository, but what if you want to share your repository with a larger audience.
22 | As stated earlier, the implementation of the tools in our testing was suitable for merely that, testing.
23 | In a production environment one would should never use the instaweb tool for a providing a permanent setup where people can browse a repository over HTTP.
24 |
25 | There are two distinct methods for handling the distribution of Git repositories to larger audiences.
26 | Generally people will either, set up the server themselves or use a third party system to host their repositories.
27 |
28 | \subsubsection{GitHub}
29 | No book on Git would be complete without at least a small section on GitHub.
30 | GitHub is a third party site for hosting and interacting with Git repositories.
31 | All of the information about GitHub is correct at the time of going to print.
32 |
33 | GitHub offers the ability to host both public and private repositories.
34 | Public repositories can be hosted for free, whereas private repositories require a subscription fee, however the pricing is tiered to allow you to start small and gradually grow your usage.
35 | Repositories can be pulled via HTTPS, SSH and Git protocols which allows you to be entirely flexible in the methods you use to keep up to date.
36 | Pushing to the repositories can be achieved via HTTPS or SSH, which again is rather flexible.
37 |
38 | The real beauty of GitHub is how it is presented.
39 | GitHub has a tagline of \emph{Social Coding} and it really does live up to that name.
40 | People can fork your project, which basically means they have cloned it to their account in GitHub.
41 | Whenever they make commits to their fork, you can see these changes pop up in a section of the site called Network.
42 |
43 | GitHub also allows you to edit files directly on the site and commit them.
44 | This means that wherever you are, as long as you have a connection to the Internet and a browser, you can edit files in your repository and commit them.
45 | When you return home, you can issue a pull and the changes will appear on your local system.
46 |
47 | For open source projects, GitHub really does offer a wealth of features for collaborative coding.
48 | When a collaborator has made enough changes to fix a bug or a feature, they can issue a pull request.
49 | This sends a notification to you that Person X would like you to merge their changes into your branch.
50 | If there are no conflicts these pull requests can be manage straight from GitHub, without requiring you to checkout the remote branch, merge it and push it back again.
51 | You can also comment on lines in the diff and many more features.
52 |
53 | Indeed during the writing of this book, several contributors used GitHub to make pull requests containing spelling mistakes and design suggestions.
54 |
55 | \subsubsection{Hosting yourself}
56 | Many people choose to host themselves, be it for security or control reasons.
57 | Sometimes people do not want to have their data \emph{online} and prefer to keep it internal to the company, this may be due to IP, license or other restrictions.
58 | However, it should be noted that this option does not pose a problem to the implementation of Git.
59 | Though you may not have access to the fancy interface features of GitHub, you still get the raw power of Git in your workplace.
60 |
61 | Apache is a common implementation of Git for companies as it is a robust webserver which offers the ability to serve and receive data through HTTP and HTTPS with a Git repository.
62 | We are not going to go into the implementation details of such a set up as each one is different.
63 | There are many tutorials on the Internet that deal with such set ups in different situations and for different purposes.
64 |
65 | SSH is also a good choice for implementing a Git repository and there are several means of securing the Git repository to allow only certain users access to certain paths etc.
66 | Git by default does not really have a security access control layer but then that is realy by design more than anything else.
67 | Git was intended to be used by open source projects to share and collaborate on code.
68 | However, this does not mean it can not be used on closed source projects, just that sometimes some modifications need to be made if more advanced features like access control are required.
69 | Many people rely on the work flow processes to ensure that things are done in a secure manner.
70 | If you have a blessed repository and have some dictators who are responsible for integrating code into it, it should be up to them to ensure that Developer X does not try to commit changes to Module Y.
71 |
72 | \subsection{Taking out the garbage}
73 | Something that we glossed over is the subject of garbage collection.
74 | Git handles this for us, routinely deleting objects that are older than a certain time period from the object database, as long as they are no longer referenced by any branches.
75 | So by this we mean that an object that exists only in one branch will only remain imune to garbage collection whilst that branch is alive.
76 | As soon as we delete the branch, all objects that are not longer referred to in any tree are left in a \emph{dangling} state and may be deleted when garbage collection runs.
77 | Of course as stated earlier, Git holds on to objects for a period of time for you, to make sure you do not do anything silly, like delete a branch you actually really wanted.
78 | You can invoke a garbage collection manually, but it is often better to let Git handle these things for you, unless you have a specific reason for doing so.
79 |
80 | \subsection{But how do you really know....you know?}
81 | When obtaining source code via an insecure means, over the Internet for example,
82 | there are times when you would really like to be as sure as possible that someone has not tampered with it.
83 | Let us take an example of someone distributing their content using a Git repository.
84 | An attacker takes control of the repository, puts in some malware and tags the commit as release version 1.0.
85 | People start do download it and as you can imagine all hell breaks loose.
86 |
87 | It does not have to be this way.
88 | Many developers and Internet users use GPG to encrypt and sign their emails and documents.
89 | GPG is a tool which can be employed to both encrypt files so that they can only be read by the intended recipient, or to sign documents and files, such that you can be reasonably sure that document is the same as when the person signed it.
90 | The private GPG \emph{key} of the signing party is used along with the file to generate a code which is sent along with the email.
91 | When it reaches the recipient a check can be made against the users public key and the content of the email, to validate that said user did actually sign that particular document or file.
92 |
93 | Git allows you to use GPG signing for tags.
94 | This gives people piece of mind that unless an attacker has gained access to both the repository and the developers private GPG key, if the sign a tag, that tag is exactly as it was intended.
95 | To use Git in this way, you must first set up a GPG key, which is out of scope of this book.
96 | Once you have this key, you can change your config like the example below, to tell Git to use a particular key when signing.
97 |
98 | \begin{code}
99 | git config user.signingkey 0xABCDEFG
100 | \end{code}
101 |
102 | Then when you want to sign a tag, simply append the \texttt{-s} parameter to the \texttt{git tag} command.
103 | You can also verify someone elses signed tag by running \texttt{git tag -v }
104 |
105 | \section{The end of the journey}
106 | Well we have reached the end of our journey.
107 | We have taken a look at many of the aspects of both Git and the mechanisms by which it can be used.
108 | As the workflow of actually using Git is so open, you will have to decide for yourself how you want to collaborate with others.
109 | Do not worry if you do not get it right first time.
110 | Try a test repository and make up scenarios, just like we have in the book, to test your workflows.
111 |
112 | Using a version control system is not an exact science and should never be something that people dislike so much that they resent using it.
113 | A good implementation of a version control system invents minimal work for the users, whilst giving themall the benefits we have desribed throughout.
114 | Remember if your users dislike the system, the chances are they will not use it properly and sometimes will try at every stage to avoid it.
115 | Help them to understand why you are using a version control system and get them onside early.
116 | You will find the procedure will be much less painless.
117 |
118 | Before we sign off for good, let us take one more trip back to the trenches to see how things panned out.
119 |
120 | \begin{trenches}
121 | ``Well I have to say guys there were points during this project that I didn't think we'd ever complete it'' said Markus with a grin on his face.
122 | The rest of the team all smiled, including Klaus.
123 |
124 | ``It wasn't the easiest thing we've ever done,'' started John, ``but it sure has helped us out in so many ways.''
125 | Markus grinned, ``Well ya big bunch of gits, hows about we head off early today and take a trip to the pub. First round is on me.''
126 |
127 | The room roared with shouts and cheers as they began to file out of the room, gather their things and head towards the Dog and Duck.
128 |
129 | \thoughtbreak
130 |
131 | The team had been in the pub for well over two hours and several of Tamagoyaki Inc's were beginning to feel the effects of the consumption of alcohol.
132 | Martha and John had broken away from the rest of the pack and were sat on a table on their own.
133 | It hadn't been intentional, but their conversation hadn't seemed to fit with the rest of the team.
134 |
135 | ``Thanks for all the help John,'' started Martha, ``You've been really good to me.''
136 |
137 | ``Hey! I'm just glad you're on my team.'' he replied. ''We certainly couldn't have done it without you.''
138 |
139 | At that point the effects of the alchopop were too much for Martha.
140 | Her cheeks began to flush a bright shade of red, and in a totally out of character manouver she leant across the table and kissed John.
141 |
142 | The rest of the team caught a glimpse of the events taking place in the isolated environment and cheered loudly.
143 |
144 | ``Geee, it's about time,'' jeered Klaus.
145 | \end{trenches}
146 |
147 |
148 |
--------------------------------------------------------------------------------
/gitt.cls:
--------------------------------------------------------------------------------
1 | %
2 | % Book design for Git in the Trenches
3 | %
4 |
5 | \NeedsTeXFormat{LaTeX2e}[1994/06/01]
6 |
7 | \ProvidesClass{gitt}[2011/05/15 v1.0.0 GITT book design]
8 |
9 | \RequirePackage{xifthen}
10 |
11 | % The 'screen' option creates a PDF suitable for reading on a computer screen
12 | % The 'print' option creates a PDF suitable for printing
13 | \providecommand{\gitt@format}{screen}% default format
14 | \DeclareOption{screen}{\gdef\gitt@format{screen}}
15 | \DeclareOption{print}{\gdef\gitt@format{print}}
16 |
17 | \newboolean{gitt@debug}
18 | \setboolean{gitt@debug}{false}
19 | \DeclareOption{debug}{\setboolean{gitt@debug}{true}}
20 |
21 | % All other options are passed along to the base class
22 | \DeclareOption*{%
23 | \PassOptionsToClass{\CurrentOption}{book}%
24 | }
25 | \ProcessOptions*\relax
26 |
27 |
28 | \LoadClass[openright,11pt]{book}
29 |
30 | % set paper size
31 | %\setstocksize{24.59cm}{18.90cm}
32 | %%\settrims{1.91cm}{0cm}
33 | %\settrimmedsize{\stockheight}{\stockwidth}{*}
34 | %\setlrmarginsandblock{2.79cm}{2.29cm}{*}
35 | %\setulmarginsandblock{2.91cm}{2.91cm}{*}
36 | %%\setmarginnotes{0.5cm}{2cm}{0.2cm}
37 | %\checkandfixthelayout
38 |
39 | \RequirePackage[paperheight=9.68in,paperwidth=7.44in,headheight=\baselineskip,textheight=35\baselineskip]{geometry}
40 | \ifthenelse{\equal{\gitt@format}{screen}}{%
41 | \geometry{asymmetric}%
42 | }
43 |
44 | % Some special processing for debug mode
45 | \ifthenelse{\boolean{gitt@debug}}{%
46 | %\geometry{showframe}% draws lines showing the margins
47 | \RequirePackage[letter,center,cam]{crop}% draw crop marks on the page
48 | }{}
49 |
50 | % Reset the figure numbering at the beginning of each chapter and print only
51 | % the figure number (not including the chapter number).
52 | \renewcommand{\thefigure}{\arabic{figure}}
53 |
54 | % Import packages
55 | % Load colors
56 | \PassOptionsToPackage{usenames,dvipsnames,svgnames}{xcolor}
57 | \RequirePackage{xcolor}
58 |
59 | \RequirePackage[final]{graphicx}
60 | \RequirePackage{fancyvrb,relsize}
61 | \RequirePackage{tikz}
62 | \RequirePackage{makeidx}
63 | \RequirePackage{eso-pic}
64 | \makeindex
65 |
66 |
67 | % Font settings
68 | \RequirePackage{fontspec}
69 | \setmainfont[Mapping=tex-text,Numbers=OldStyle]{Linux Libertine O}
70 | %\setsansfont[Mapping=tex-text,Scale=MatchLowercase]{LMSans10}
71 | %\setsansfont[Mapping=tex-text,Scale=MatchLowercase,SmallCapsFont={* Small Caps}]{Fontin Sans}
72 | %\setsansfont[Mapping=tex-text,Scale=MatchLowercase]{PT Sans}
73 | \setmonofont[Mapping=tex-text,Scale=MatchLowercase]{DejaVu Sans Mono}
74 |
75 |
76 | % Small caps
77 | \newcommand{\smallcaps}[1]{%
78 | {\addfontfeature{LetterSpace=5.0}\textsc{\MakeTextLowercase{#1}}}%
79 | }
80 |
81 | % Running heads and feet
82 | \RequirePackage{textcase}
83 | \RequirePackage{fancyhdr}
84 | \pagestyle{fancy}
85 | \fancyhf{}
86 | \fancyhead[LE]{\thepage\quad\smallcaps{\leftmark}}
87 | \fancyhead[RO]{\smallcaps{\rightmark}\quad\thepage}
88 | \renewcommand{\headrulewidth}{0pt}
89 |
90 | % Front matter
91 | \renewcommand\frontmatter{%
92 | \cleardoublepage%
93 | \@mainmatterfalse%
94 | \pagenumbering{roman}%
95 | \fancyhf{}%
96 | \renewcommand{\chaptermark}[1]{\markboth{##1}{}}%
97 | \renewcommand{\sectionmark}[1]{\markright{##1}}%
98 | \fancyhead[LE]{\thepage\quad\smallcaps{\leftmark}}% chapter title
99 | \fancyhead[RO]{\smallcaps{\rightmark}\quad\thepage}% section title
100 | }
101 |
102 | % Main matter
103 | \renewcommand\mainmatter{%
104 | \cleardoublepage%
105 | \@mainmattertrue%
106 | \pagenumbering{arabic}%
107 | \fancyhf{}%
108 | \renewcommand{\chaptermark}[1]{\markboth{##1}{}}%
109 | \renewcommand{\sectionmark}[1]{\markright{##1}}%
110 | \fancyhead[LE]{\thepage\quad\smallcaps{\leftmark}}% chapter title
111 | \fancyhead[RO]{\smallcaps{\rightmark}\quad\thepage}% section title
112 | }
113 |
114 |
115 |
116 |
117 | % When cleardoublepage is called, produce a blank (empty) page -- i.e.,
118 | % without headers and footers
119 | \def\cleardoublepage{%
120 | \clearpage
121 | \if@twoside%
122 | \ifodd\c@page\else
123 | \hbox{}%
124 | %\vspace*{\fill}
125 | %\begin{center}
126 | % This page intentionally contains only this sentence.
127 | %\end{center}
128 | %\vspace{\fill}
129 | \thispagestyle{empty}%
130 | \newpage%
131 | \if@twocolumn\hbox{}\newpage\fi%
132 | \fi%
133 | \fi%
134 | }
135 |
136 |
137 |
138 |
139 | % Put chapters and sections in the toc, only number the chapter
140 | \setcounter{tocdepth}{3}
141 | \setcounter{secnumdepth}{0}
142 |
143 | % Make chapter names disappear
144 | \renewcommand{\chaptername}{}
145 | \renewcommand{\thechapter}{}
146 | \renewcommand{\tablename}{}
147 | \renewcommand{\thetable}{}
148 |
149 | % Print just the chapter name without 'Chapter #.' in the running heads
150 | %\renewcommand\chaptermark[1]{\markboth{\memUChead{#1}}{}}%
151 |
152 | % Make the pdf have clickable links
153 | \RequirePackage{hyperref}
154 |
155 | \hypersetup{%
156 | bookmarks,
157 | bookmarksopen,
158 | bookmarksnumbered=false,
159 | colorlinks=true,
160 | pdfpagemode=None,
161 | pdfborder = {0 0 0},
162 | citecolor = DarkGreen,
163 | linkcolor = DarkBlue,
164 | urlcolor = DarkGreen,
165 | plainpages=false,
166 | pdfpagelabels,
167 | pdftitle={Git in the Trenches},
168 | pdfauthor={Peter Savage}
169 | }
170 |
171 | % Use black link colors for print edition
172 | \ifthenelse{\equal{\gitt@format}{print}}{%
173 | \hypersetup{%
174 | colorlinks=false
175 | }%
176 | }
177 |
178 | \AtBeginDocument{
179 | \hyphenpenalty=1000
180 | \tolerance=1000
181 | }
182 |
183 | % give us a begin{trenches}
184 | \newenvironment{trenches}{%
185 | \begin{quote}%
186 | \begin{sffamily}%
187 | \noindent\textbf{In the trenches\ldots}\quad%
188 | }{%
189 | \end{sffamily}%
190 | \end{quote}%
191 | }
192 |
193 | % Callout boxes
194 | \newsavebox{\callout@contents}
195 | \newcommand{\callout@type}{}
196 | \newcommand{\callout@title}{}
197 | \newenvironment{callout}[2]{%
198 | \xdef\callout@type{#1}% typeset in a box along the left
199 | \xdef\callout@title{#2}% typeset in a box along the top
200 | \begin{lrbox}{\callout@contents}%
201 | \begin{minipage}{\textwidth-30pt}%
202 | }{%
203 | \end{minipage}%
204 | \end{lrbox}%
205 | \begin{figure}[hbt]%
206 | \tikzstyle{mybox} = [draw=black, fill=gray!20, very thick, rectangle, rounded corners, inner sep=15pt, inner ysep=20pt, font={\sffamily\bfseries}]
207 | \tikzstyle{fancytitle} = [fill=black, text=white, font={\sffamily\bfseries}]
208 | \hskip-10pt% allows the type block to hang into the left margin
209 | \begin{tikzpicture}%
210 | \node[mybox] (box) {\usebox{\callout@contents}};
211 | \node[fancytitle, right=16pt] at (box.north west) {\callout@title};
212 | \node[fancytitle, rounded corners] at (box.west) {\rotatebox{90}{\callout@type}};
213 | \end{tikzpicture}%
214 | \end{figure}%
215 | }
216 |
217 | % Indicates thought breaks
218 | \newcommand{\thoughtbreak}{%
219 | \par\begin{center}*\quad*\quad*\end{center}\par
220 | }
221 |
222 | % Clear page commands from memoir.cls
223 | \newcommand{\cleartoevenpage}[1][\@empty]{%
224 | \clearpage%
225 | \ifodd\c@page\hbox{}#1\clearpage\fi%
226 | }
227 |
228 | \newcommand{\cleartooddpage}[1][\@empty]{%
229 | \clearpage%
230 | \ifodd\c@page\else\hbox{}#1\clearpage\fi%
231 | }
232 |
233 |
234 | % Inserts full-page graphics for cover pages.
235 | \newcommand{\coverpage}[1]{%
236 | \thispagestyle{empty}%
237 | \IfFileExists{#1}{%
238 | \AddToShipoutPicture*{\put(0,0){\includegraphics[width=\paperwidth,height=\paperheight]{#1}}}%
239 | }{%
240 | \ClassWarningNoLine{gitt}{Missing cover page graphic:\MessageBreak #1}%
241 | }%
242 | }
243 |
244 | \newcommand{\frontcover}[1]{%
245 | \ifthenelse{\equal{\gitt@format}{screen}}{%
246 | \coverpage{#1}%
247 | \null\cleardoublepage
248 | }{%
249 | \ClassWarningNoLine{gitt}{Ignoring \string\frontcover because we're not generating a screen format.}%
250 | }%
251 | }
252 |
253 | \newcommand{\backcover}[1]{%
254 | \ifthenelse{\equal{\gitt@format}{screen}}{%
255 | \cleartoevenpage[\thispagestyle{empty}]%
256 | \coverpage{#1}%
257 | \null%
258 | }{%
259 | \ClassWarningNoLine{gitt}{Ignoring \string\backcover because we're not generating a screen format.}%
260 | }%
261 | }
262 |
263 | \newcommand{\indexref}[1]{%
264 | \index{#1|textit}%
265 | }
266 |
267 | \newcommand{\indexcom}[2]{%
268 | \index{#1@\texttt{#2}}%
269 | }
270 |
271 | \newcommand{\indexgit}[1]{%
272 | \texttt{git #1}%
273 | \index{git commands!#1@\texttt{#1}}%
274 | }
275 |
276 | \newcommand{\figuregit}[3]{%
277 | \begin{figure}[bt]%
278 | \centering
279 | \includegraphics[width=#1]{#2}%
280 | \caption{#3}%
281 | \end{figure}%
282 | }
283 |
284 | \newcommand{\figuregith}[3]{%
285 | \begin{figure}[hbt]%
286 | \centering
287 | \includegraphics[width=#1]{#2}%
288 | \caption{#3}%
289 | \end{figure}%
290 | }
291 |
292 | \RequirePackage{listings}
293 | \lstnewenvironment{code}{
294 | \lstset{
295 | basicstyle=\footnotesize\ttfamily,
296 | identifierstyle=\footnotesize\ttfamily,
297 | commentstyle=\footnotesize\ttfamily,
298 | stringstyle=\footnotesize\ttfamily,
299 | keywordstyle=\footnotesize\bfseries\ttfamily,
300 | frame=leftline,
301 | rulecolor=\color{lightgray},
302 | framerule=1mm,
303 | framextopmargin=0pt,
304 | framexbottommargin=0pt,
305 | framexleftmargin=2pt,
306 | framexrightmargin=2pt,
307 | xleftmargin=8pt,
308 | xrightmargin=2pt,
309 | breaklines=true,
310 | breakatwhitespace=true,
311 | breakindent=4pt,
312 | postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookrightarrow}},
313 | tabsize=2,
314 | showstringspaces=false,
315 | aboveskip=\abovedisplayskip,
316 | belowskip=\belowdisplayskip,
317 | morecomment=[l][\footnotesize\bfseries\ttfamily]{john@satsuki:},
318 | morecomment=[l][\footnotesize\bfseries\ttfamily]{rob@mimi:}
319 | %moredelim=[is][\tiny\bfseries\ttfamily]{|||}{|||}
320 | }
321 | }{}
322 |
323 | % Table of contents
324 | \renewcommand\tableofcontents{%
325 | \if@twocolumn
326 | \@restonecoltrue\onecolumn
327 | \else
328 | \@restonecolfalse
329 | \fi
330 | \chapter*{\contentsname
331 | \@mkboth{\contentsname}{\contentsname}
332 | }%
333 | \@starttoc{toc}%
334 | \if@restonecol\twocolumn\fi
335 | }
336 |
337 | % Index
338 | \renewenvironment{theindex}{%
339 | \if@twocolumn
340 | \@restonecolfalse
341 | \else
342 | \@restonecoltrue
343 | \fi
344 | \twocolumn[\@makeschapterhead{\indexname}]%
345 | \@mkboth{\indexname}{\indexname}%
346 | \thispagestyle{plain}%
347 | \parindent\z@
348 | \parskip\z@ \@plus .3\p@\relax
349 | \columnseprule \z@
350 | \columnsep 35\p@
351 | \let\item\@idxitem
352 | }{%
353 | \if@restonecol
354 | \onecolumn
355 | \else
356 | \clearpage
357 | \fi
358 | }
359 |
360 | % Headings
361 | \RequirePackage{titlesec}
362 |
363 | \titleformat{\chapter}%
364 | [hang]% shape
365 | {\sffamily\huge\itshape\bfseries}% format applied to label+text
366 | {\thechapter}% label
367 | {0pt}% horizontal separation between label and title body
368 | {\sffamily\huge\itshape}% before the title body
369 | []% after the title body
370 |
371 | \titleformat{\section}%
372 | [hang]% shape
373 | {\sffamily\Large\itshape\bfseries}% format applied to label+text
374 | {\thesection}% label
375 | {1em}% horizontal separation between label and title body
376 | {}% before the title body
377 | []% after the title body
378 |
379 | \titleformat{\subsection}%
380 | [hang]% shape
381 | {\sffamily\large\itshape\bfseries}% format applied to label+text
382 | {\thesubsection}% label
383 | {1em}% horizontal separation between label and title body
384 | {}% before the title body
385 | []% after the title body
386 |
387 | \titleformat{\subsubsection}%
388 | [hang]% shape
389 | {\sffamily\normalsize\itshape\bfseries}% format applied to label+text
390 | {\thesubsection}% label
391 | {1em}% horizontal separation between label and title body
392 | {}% before the title body
393 | []% after the title body
394 |
395 | \titleformat{\paragraph}%
396 | [runin]% shape
397 | {\normalfont\itshape}% format applied to label+text
398 | {\theparagraph}% label
399 | {1em}% horizontal separation between label and title body
400 | {}% before the title body
401 | []% after the title body
402 |
403 | \titlespacing*{\chapter}{0pt}{2\baselineskip}{1\baselineskip}
404 | \titlespacing*{\section}{0pt}{2.5ex plus 1ex minus 1ex}{1.3ex plus .2ex minus .2ex}
405 | \titlespacing*{\subsection}{0pt}{2.25ex plus 1ex minus .75ex}{0.7ex plus.2ex minus .2ex}
406 | \titlespacing*{\subsubsection}{0pt}{1.25ex plus 1ex minus .2ex}{0.7ex plus.2ex minus .2ex}
407 |
408 |
409 | % Float placement parameters
410 | \setcounter{topnumber}{3}
411 | \setcounter{bottomnumber}{2}
412 | \setcounter{totalnumber}{4}
413 | \renewcommand{\topfraction}{0.9}
414 | \renewcommand{\bottomfraction}{0.1}
415 | \renewcommand{\textfraction}{0.1}
416 | \renewcommand{\dbltopfraction}{\topfraction}
417 | \renewcommand{\floatpagefraction}{0.7}
418 | \renewcommand{\dblfloatpagefraction}{0.5}
419 |
420 |
421 | % Caption formatting
422 | \RequirePackage{caption}
423 | \captionsetup{%
424 | font={small,sf},
425 | }
426 |
427 |
--------------------------------------------------------------------------------
/gitt.tex:
--------------------------------------------------------------------------------
1 | \providecommand{\mediaformat}{screen}
2 | \documentclass[\mediaformat]{gitt}
3 |
4 | % Title/author/date
5 | \title{Git in the Trenches}
6 | \author{Peter Savage}
7 | \date{August 2011}
8 |
9 | \begin{document}
10 |
11 | % Front cover
12 | \frontcover{images/fcover-new.pdf}
13 |
14 | % Front matter
15 | \frontmatter
16 | \maketitle
17 | \cleardoublepage
18 | \tableofcontents
19 |
20 | % Main matter
21 | % DO NOT REMOVE THE LINE BELOW
22 | \mainmatter
23 | \include{intro}
24 | \include{setup}
25 | \include{chap1}
26 | \include{afterhours1}
27 | \include{chap2}
28 | \include{afterhours2}
29 | \include{chap3}
30 | \include{afterhours3}
31 | \include{chap4}
32 | \include{afterhours4}
33 | \include{chap5}
34 | \include{afterhours5}
35 | \include{chap6}
36 | \include{afterhours6}
37 | \include{chap7}
38 | \include{afterhours7}
39 | \include{chap8}
40 | \include{afterhours8}
41 | \include{chap9}
42 |
43 | % Back matter
44 | % DO NOT REMOVE THE LINE BELOW
45 | \backmatter
46 | \include{ack}
47 | \include{index}
48 |
49 | % Back cover
50 | \backcover{images/bcover-new.pdf}
51 |
52 | \end{document}
53 |
54 |
--------------------------------------------------------------------------------
/html/base-foot.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |