Skip to content

Commit ec27d50

Browse files
committed
migrated tons more content from the user guide and tutorials - about time to edit
1 parent e2f49cd commit ec27d50

File tree

28 files changed

+1152
-26
lines changed

28 files changed

+1152
-26
lines changed

assets/stylesheets/style.css

+2
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ table tr td { vertical-align: top;}
5959

6060
table.data-table tr td { vertical-align: top;}
6161
table.data-table tr td h3 { background: #B5463F; color: #fff; padding: 5px; }
62+
63+
pre { background: #eee; padding: 5px;}

layout/second.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ table.lined td, table.lined th {
162162
@page :left {
163163
@top-left {
164164
font: 11pt "Gill Sans", serif;
165-
content: "Ruby on Rails 2.1 - What's New";
165+
content: "Git Community Book";
166166
vertical-align: bottom;
167167
padding-bottom: 2em;
168168
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
11
## Normal Workflow ##
22

3-
(modifying, adding, commiting)
3+
Modify some files, then add their updated contents to the index:
4+
5+
$ git add file1 file2 file3
6+
7+
You are now ready to commit. You can see what is about to be committed
8+
using linkgit:git-diff[1] with the --cached option:
9+
10+
$ git diff --cached
11+
12+
(Without --cached, linkgit:git-diff[1] will show you any changes that
13+
you've made but not yet added to the index.) You can also get a brief
14+
summary of the situation with linkgit:git-status[1]:
15+
16+
$ git status
17+
# On branch master
18+
# Changes to be committed:
19+
# (use "git reset HEAD <file>..." to unstage)
20+
#
21+
# modified: file1
22+
# modified: file2
23+
# modified: file3
24+
#
25+
26+
If you need to make any further adjustments, do so now, and then add any
27+
newly modified content to the index. Finally, commit your changes with:
28+
29+
$ git commit
30+
31+
This will again prompt your for a message describing the change, and then
32+
record a new version of the project.
33+
34+
Alternatively, instead of running `git add` beforehand, you can use
35+
36+
$ git commit -a
37+
38+
which will automatically notice any modified (but not new) files, add
39+
them to the index, and commit, all in one step.
40+
41+
A note on commit messages: Though not required, it's a good idea to
42+
begin the commit message with a single short (less than 50 character)
43+
line summarizing the change, followed by a blank line and then a more
44+
thorough description. Tools that turn commits into email, for
45+
example, use the first line on the Subject: line and the rest of the
46+
commit in the body.
47+
48+
49+
#### Git tracks content not files ####
50+
51+
Many revision control systems provide an "add" command that tells the
52+
system to start tracking changes to a new file. Git's "add" command
53+
does something simpler and more powerful: `git add` is used both for new
54+
and newly modified files, and in both cases it takes a snapshot of the
55+
given files and stages that content in the index, ready for inclusion in
56+
the next commit.
Original file line numberDiff line numberDiff line change
@@ -1 +1,164 @@
1-
##Basic Branching and Merging
1+
## Basic Branching and Merging ##
2+
3+
A single git repository can maintain multiple branches of
4+
development. To create a new branch named "experimental", use
5+
6+
$ git branch experimental
7+
8+
If you now run
9+
10+
$ git branch
11+
12+
you'll get a list of all existing branches:
13+
14+
experimental
15+
* master
16+
17+
The "experimental" branch is the one you just created, and the
18+
"master" branch is a default branch that was created for you
19+
automatically. The asterisk marks the branch you are currently on;
20+
type
21+
22+
$ git checkout experimental
23+
24+
to switch to the experimental branch. Now edit a file, commit the
25+
change, and switch back to the master branch:
26+
27+
(edit file)
28+
$ git commit -a
29+
$ git checkout master
30+
31+
Check that the change you made is no longer visible, since it was
32+
made on the experimental branch and you're back on the master branch.
33+
34+
You can make a different change on the master branch:
35+
36+
(edit file)
37+
$ git commit -a
38+
39+
at this point the two branches have diverged, with different changes
40+
made in each. To merge the changes made in experimental into master, run
41+
42+
$ git merge experimental
43+
44+
If the changes don't conflict, you're done. If there are conflicts,
45+
markers will be left in the problematic files showing the conflict;
46+
47+
$ git diff
48+
49+
will show this. Once you've edited the files to resolve the
50+
conflicts,
51+
52+
$ git commit -a
53+
54+
will commit the result of the merge. Finally,
55+
56+
$ gitk
57+
58+
will show a nice graphical representation of the resulting history.
59+
60+
At this point you could delete the experimental branch with
61+
62+
$ git branch -d experimental
63+
64+
This command ensures that the changes in the experimental branch are
65+
already in the current branch.
66+
67+
If you develop on a branch crazy-idea, then regret it, you can always
68+
delete the branch with
69+
70+
$ git branch -D crazy-idea
71+
72+
Branches are cheap and easy, so this is a good way to try something
73+
out.
74+
75+
### How to merge ###
76+
77+
You can rejoin two diverging branches of development using
78+
linkgit:git-merge[1]:
79+
80+
$ git merge branchname
81+
82+
merges the development in the branch "branchname" into the current
83+
branch. If there are conflicts--for example, if the same file is
84+
modified in two different ways in the remote branch and the local
85+
branch--then you are warned; the output may look something like this:
86+
87+
$ git merge next
88+
100% (4/4) done
89+
Auto-merged file.txt
90+
CONFLICT (content): Merge conflict in file.txt
91+
Automatic merge failed; fix conflicts and then commit the result.
92+
93+
Conflict markers are left in the problematic files, and after
94+
you resolve the conflicts manually, you can update the index
95+
with the contents and run git commit, as you normally would when
96+
creating a new file.
97+
98+
If you examine the resulting commit using gitk, you will see that it
99+
has two parents, one pointing to the top of the current branch, and
100+
one to the top of the other branch.
101+
102+
### Resolving a merge ###
103+
104+
When a merge isn't resolved automatically, git leaves the index and
105+
the working tree in a special state that gives you all the
106+
information you need to help resolve the merge.
107+
108+
Files with conflicts are marked specially in the index, so until you
109+
resolve the problem and update the index, linkgit:git-commit[1] will
110+
fail:
111+
112+
$ git commit
113+
file.txt: needs merge
114+
115+
Also, linkgit:git-status[1] will list those files as "unmerged", and the
116+
files with conflicts will have conflict markers added, like this:
117+
118+
<<<<<<< HEAD:file.txt
119+
Hello world
120+
=======
121+
Goodbye
122+
>>>>>>> 77976da35a11db4580b80ae27e8d65caf5208086:file.txt
123+
124+
All you need to do is edit the files to resolve the conflicts, and then
125+
126+
$ git add file.txt
127+
$ git commit
128+
129+
Note that the commit message will already be filled in for you with
130+
some information about the merge. Normally you can just use this
131+
default message unchanged, but you may add additional commentary of
132+
your own if desired.
133+
134+
The above is all you need to know to resolve a simple merge. But git
135+
also provides more information to help resolve conflicts:
136+
137+
### Undoing a merge ###
138+
139+
If you get stuck and decide to just give up and throw the whole mess
140+
away, you can always return to the pre-merge state with
141+
142+
$ git reset --hard HEAD
143+
144+
Or, if you've already committed the merge that you want to throw away,
145+
146+
$ git reset --hard ORIG_HEAD
147+
148+
However, this last command can be dangerous in some cases--never
149+
throw away a commit you have already committed if that commit may
150+
itself have been merged into another branch, as doing so may confuse
151+
further merges.
152+
153+
### Fast-forward merges ###
154+
155+
There is one special case not mentioned above, which is treated
156+
differently. Normally, a merge results in a merge commit, with two
157+
parents, one pointing at each of the two lines of development that
158+
were merged.
159+
160+
However, if the current branch is a descendant of the other--so every
161+
commit present in the one is already contained in the other--then git
162+
just performs a "fast forward"; the head of the current branch is moved
163+
forward to point at the head of the merged-in branch, without any new
164+
commits being created.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,33 @@
11
## Reviewing History - Git Log ##
22

3+
The linkgit:git-log[1] command can show lists of commits. On its
4+
own, it shows all commits reachable from the parent commit; but you
5+
can also make more specific requests:
6+
7+
$ git log v2.5.. # commits since (not reachable from) v2.5
8+
$ git log test..master # commits reachable from master but not test
9+
$ git log master..test # ...reachable from test but not master
10+
$ git log master...test # ...reachable from either test or master,
11+
# but not both
12+
$ git log --since="2 weeks ago" # commits from the last 2 weeks
13+
$ git log Makefile # commits which modify Makefile
14+
$ git log fs/ # ... which modify any file under fs/
15+
$ git log -S'foo()' # commits which add or remove any file data
16+
# matching the string 'foo()'
17+
18+
And of course you can combine all of these; the following finds
19+
commits since v2.5 which touch the Makefile or any file under fs:
20+
21+
$ git log v2.5.. Makefile fs/
22+
23+
You can also ask git log to show patches:
24+
25+
$ git log -p
26+
27+
See the "--pretty" option in the linkgit:git-log[1] man page for more
28+
display options.
29+
30+
Note that git log starts with the most recent commit and works
31+
backwards through the parents; however, since git history can contain
32+
multiple independent lines of development, the particular order that
33+
commits are listed in may be somewhat arbitrary.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
## Comparing Commits - Git Diff ##
22

3+
You can generate diffs between any two versions using
4+
linkgit:git-diff[1]:
5+
6+
$ git diff master..test
7+
8+
That will produce the diff between the tips of the two branches. If
9+
you'd prefer to find the diff from their common ancestor to test, you
10+
can use three dots instead of two:
11+
12+
$ git diff master...test
13+

0 commit comments

Comments
 (0)