Skip to content

Commit f51248e

Browse files
author
Junio C Hamano
committed
Merge branch 'fixes'
2 parents f80376c + 5990efb commit f51248e

File tree

3 files changed

+218
-23
lines changed

3 files changed

+218
-23
lines changed

Documentation/tutorial.txt

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ your new project. You will now have a `.git` directory, and you can
5151
inspect that with `ls`. For your new empty project, it should show you
5252
three entries, among other things:
5353

54-
- a symlink called `HEAD`, pointing to `refs/heads/master`
54+
- a symlink called `HEAD`, pointing to `refs/heads/master` (if your
55+
platform does not have native symlinks, it is a file containing the
56+
line "ref: refs/heads/master")
5557
+
5658
Don't worry about the fact that the file that the `HEAD` link points to
5759
doesn't even exist yet -- you haven't created the commit that will
@@ -227,6 +229,7 @@ which will spit out
227229

228230
------------
229231
diff --git a/hello b/hello
232+
index 557db03..263414f 100644
230233
--- a/hello
231234
+++ b/hello
232235
@@ -1 +1,2 @@
@@ -289,13 +292,16 @@ also wants to get a commit message
289292
on its standard input, and it will write out the resulting object name for the
290293
commit to its standard output.
291294

292-
And this is where we start using the `.git/HEAD` file. The `HEAD` file is
293-
supposed to contain the reference to the top-of-tree, and since that's
294-
exactly what `git-commit-tree` spits out, we can do this all with a simple
295-
shell pipeline:
295+
And this is where we create the `.git/refs/heads/master` file
296+
which is pointed at by `HEAD`. This file is supposed to contain
297+
the reference to the top-of-tree of the master branch, and since
298+
that's exactly what `git-commit-tree` spits out, we can do this
299+
all with a sequence of simple shell commands:
296300

297301
------------------------------------------------
298-
echo "Initial commit" | git-commit-tree $(git-write-tree) > .git/HEAD
302+
tree=$(git-write-tree)
303+
commit=$(echo 'Initial commit' | git-commit-tree $tree)
304+
git-update-ref HEAD $(commit)
299305
------------------------------------------------
300306

301307
which will say:
@@ -691,33 +697,49 @@ other point in the history than the current `HEAD`, you can do so by
691697
just telling `git checkout` what the base of the checkout would be.
692698
In other words, if you have an earlier tag or branch, you'd just do
693699

694-
git checkout -b mybranch earlier-commit
700+
------------
701+
git checkout -b mybranch earlier-commit
702+
------------
695703

696704
and it would create the new branch `mybranch` at the earlier commit,
697705
and check out the state at that time.
698706
================================================
699707

700708
You can always just jump back to your original `master` branch by doing
701709

702-
git checkout master
710+
------------
711+
git checkout master
712+
------------
703713

704714
(or any other branch-name, for that matter) and if you forget which
705715
branch you happen to be on, a simple
706716

707-
ls -l .git/HEAD
717+
------------
718+
ls -l .git/HEAD
719+
------------
708720

709-
will tell you where it's pointing. To get the list of branches
710-
you have, you can say
721+
will tell you where it's pointing (Note that on platforms with bad or no
722+
symlink support, you have to execute
711723

712-
git branch
724+
------------
725+
cat .git/HEAD
726+
------------
727+
728+
instead). To get the list of branches you have, you can say
729+
730+
------------
731+
git branch
732+
------------
713733

714734
which is nothing more than a simple script around `ls .git/refs/heads`.
715735
There will be asterisk in front of the branch you are currently on.
716736

717737
Sometimes you may wish to create a new branch _without_ actually
718738
checking it out and switching to it. If so, just use the command
719739

720-
git branch <branchname> [startingpoint]
740+
------------
741+
git branch <branchname> [startingpoint]
742+
------------
721743

722744
which will simply _create_ the branch, but will not do anything further.
723745
You can then later -- once you decide that you want to actually develop
@@ -843,7 +865,6 @@ $ git show-branch master mybranch
843865
! [mybranch] Some work.
844866
--
845867
+ [master] Merged "mybranch" changes.
846-
+ [master~1] Some fun.
847868
++ [mybranch] Some work.
848869
------------------------------------------------
849870

@@ -870,8 +891,10 @@ Now, let's pretend you are the one who did all the work in
870891
to the `master` branch. Let's go back to `mybranch`, and run
871892
resolve to get the "upstream changes" back to your branch.
872893

873-
git checkout mybranch
874-
git resolve HEAD master "Merge upstream changes."
894+
------------
895+
git checkout mybranch
896+
git resolve HEAD master "Merge upstream changes."
897+
------------
875898

876899
This outputs something like this (the actual commit object names
877900
would be different)
@@ -1087,13 +1110,17 @@ i.e. `<project>.git`. Let's create such a public repository for
10871110
project `my-git`. After logging into the remote machine, create
10881111
an empty directory:
10891112

1090-
mkdir my-git.git
1113+
------------
1114+
mkdir my-git.git
1115+
------------
10911116

10921117
Then, make that directory into a git repository by running
10931118
`git init-db`, but this time, since its name is not the usual
10941119
`.git`, we do things slightly differently:
10951120

1096-
GIT_DIR=my-git.git git-init-db
1121+
------------
1122+
GIT_DIR=my-git.git git-init-db
1123+
------------
10971124

10981125
Make sure this directory is available for others you want your
10991126
changes to be pulled by via the transport of your choice. Also
@@ -1117,7 +1144,9 @@ Your "public repository" is now ready to accept your changes.
11171144
Come back to the machine you have your private repository. From
11181145
there, run this command:
11191146

1120-
git push <public-host>:/path/to/my-git.git master
1147+
------------
1148+
git push <public-host>:/path/to/my-git.git master
1149+
------------
11211150

11221151
This synchronizes your public repository to match the named
11231152
branch head (i.e. `master` in this case) and objects reachable
@@ -1127,7 +1156,9 @@ As a real example, this is how I update my public git
11271156
repository. Kernel.org mirror network takes care of the
11281157
propagation to other publicly visible machines:
11291158

1130-
git push master.kernel.org:/pub/scm/git/git.git/
1159+
------------
1160+
git push master.kernel.org:/pub/scm/git/git.git/
1161+
------------
11311162

11321163

11331164
Packing your repository
@@ -1140,7 +1171,9 @@ not so convenient to transport over the network. Since git objects are
11401171
immutable once they are created, there is a way to optimize the
11411172
storage by "packing them together". The command
11421173

1143-
git repack
1174+
------------
1175+
git repack
1176+
------------
11441177

11451178
will do it for you. If you followed the tutorial examples, you
11461179
would have accumulated about 17 objects in `.git/objects/??/`
@@ -1164,7 +1197,9 @@ Our programs are always perfect ;-).
11641197
Once you have packed objects, you do not need to leave the
11651198
unpacked objects that are contained in the pack file anymore.
11661199

1167-
git prune-packed
1200+
------------
1201+
git prune-packed
1202+
------------
11681203

11691204
would remove them for you.
11701205

rsh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int setup_connection(int *fd_in, int *fd_out, const char *remote_prog,
6868
if (!path) {
6969
return error("Bad URL: %s", url);
7070
}
71-
/* $GIT_RSH <host> "env GIR_DIR=<path> <remote_prog> <args...>" */
71+
/* $GIT_RSH <host> "env GIT_DIR=<path> <remote_prog> <args...>" */
7272
sizen = COMMAND_SIZE;
7373
posn = command;
7474
of = 0;

t/t1200-tutorial.sh

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2005 Johannes Schindelin
4+
#
5+
6+
test_description='Test git-rev-parse with different parent options'
7+
8+
. ./test-lib.sh
9+
10+
echo "Hello World" > hello
11+
echo "Silly example" > example
12+
13+
git-update-index --add hello example
14+
15+
test_expect_success 'blob' "test blob = \"$(git-cat-file -t 557db03)\""
16+
17+
test_expect_success 'blob 557db03' "test \"Hello World\" = \"$(git-cat-file blob 557db03)\""
18+
19+
echo "It's a new day for git" >>hello
20+
cat > diff.expect << EOF
21+
diff --git a/hello b/hello
22+
index 557db03..263414f 100644
23+
--- a/hello
24+
+++ b/hello
25+
@@ -1 +1,2 @@
26+
Hello World
27+
+It's a new day for git
28+
EOF
29+
git-diff-files -p > diff.output
30+
test_expect_success 'git-diff-files -p' 'cmp diff.expect diff.output'
31+
git diff > diff.output
32+
test_expect_success 'git diff' 'cmp diff.expect diff.output'
33+
34+
tree=$(git-write-tree 2>/dev/null)
35+
36+
test_expect_success 'tree' "test 8988da15d077d4829fc51d8544c097def6644dbb = $tree"
37+
38+
output="$(echo "Initial commit" | git-commit-tree $(git-write-tree) 2>&1 > .git/refs/heads/master)"
39+
40+
test_expect_success 'commit' "test 'Committing initial tree 8988da15d077d4829fc51d8544c097def6644dbb' = \"$output\""
41+
42+
git-diff-index -p HEAD > diff.output
43+
test_expect_success 'git-diff-index -p HEAD' 'cmp diff.expect diff.output'
44+
45+
git diff HEAD > diff.output
46+
test_expect_success 'git diff HEAD' 'cmp diff.expect diff.output'
47+
48+
#rm hello
49+
#test_expect_success 'git-read-tree --reset HEAD' "git-read-tree --reset HEAD ; test \"hello: needs update\" = \"$(git-update-index --refresh)\""
50+
51+
cat > whatchanged.expect << EOF
52+
diff-tree VARIABLE (from root)
53+
Author: VARIABLE
54+
Date: VARIABLE
55+
56+
Initial commit
57+
58+
diff --git a/example b/example
59+
new file mode 100644
60+
index 0000000..f24c74a
61+
--- /dev/null
62+
+++ b/example
63+
@@ -0,0 +1 @@
64+
+Silly example
65+
diff --git a/hello b/hello
66+
new file mode 100644
67+
index 0000000..557db03
68+
--- /dev/null
69+
+++ b/hello
70+
@@ -0,0 +1 @@
71+
+Hello World
72+
EOF
73+
74+
git-whatchanged -p --root | \
75+
sed -e "1s/^\(.\{10\}\).\{40\}/\1VARIABLE/" \
76+
-e "2,3s/^\(.\{8\}\).*$/\1VARIABLE/" \
77+
> whatchanged.output
78+
test_expect_success 'git-whatchanged -p --root' 'cmp whatchanged.expect whatchanged.output'
79+
80+
git tag my-first-tag
81+
test_expect_success 'git tag my-first-tag' 'cmp .git/refs/heads/master .git/refs/tags/my-first-tag'
82+
83+
# TODO: test git-clone
84+
85+
git checkout -b mybranch
86+
test_expect_success 'git checkout -b mybranch' 'cmp .git/refs/heads/master .git/refs/heads/mybranch'
87+
88+
cat > branch.expect <<EOF
89+
master
90+
* mybranch
91+
EOF
92+
93+
git branch > branch.output
94+
test_expect_success 'git branch' 'cmp branch.expect branch.output'
95+
96+
git checkout mybranch
97+
echo "Work, work, work" >>hello
98+
git commit -m 'Some work.' hello
99+
100+
git checkout master
101+
102+
echo "Play, play, play" >>hello
103+
echo "Lots of fun" >>example
104+
git commit -m 'Some fun.' hello example
105+
106+
test_expect_failure 'git resolve now fails' 'git resolve HEAD mybranch "Merge work in mybranch"'
107+
108+
cat > hello << EOF
109+
Hello World
110+
It's a new day for git
111+
Play, play, play
112+
Work, work, work
113+
EOF
114+
115+
git commit -m 'Merged "mybranch" changes.' hello
116+
117+
cat > show-branch.expect << EOF
118+
* [master] Merged "mybranch" changes.
119+
! [mybranch] Some work.
120+
--
121+
+ [master] Merged "mybranch" changes.
122+
++ [mybranch] Some work.
123+
EOF
124+
125+
git show-branch master mybranch > show-branch.output
126+
test_expect_success 'git show-branch' 'cmp show-branch.expect show-branch.output'
127+
128+
git checkout mybranch
129+
130+
cat > resolve.expect << EOF
131+
Updating from VARIABLE to VARIABLE.
132+
example | 1 +
133+
hello | 1 +
134+
2 files changed, 2 insertions(+), 0 deletions(-)
135+
EOF
136+
137+
git resolve HEAD master "Merge upstream changes." | \
138+
sed -e "1s/[0-9a-f]\{40\}/VARIABLE/g" > resolve.output
139+
test_expect_success 'git resolve' 'cmp resolve.expect resolve.output'
140+
141+
cat > show-branch2.expect << EOF
142+
! [master] Merged "mybranch" changes.
143+
* [mybranch] Merged "mybranch" changes.
144+
--
145+
++ [master] Merged "mybranch" changes.
146+
EOF
147+
148+
git show-branch master mybranch > show-branch2.output
149+
test_expect_success 'git show-branch' 'cmp show-branch2.expect show-branch2.output'
150+
151+
# TODO: test git fetch
152+
153+
# TODO: test git push
154+
155+
test_expect_success 'git repack' 'git repack'
156+
test_expect_success 'git prune-packed' 'git prune-packed'
157+
test_expect_failure '-> only packed objects' 'find -type f .git/objects/[0-9a-f][0-9a-f]'
158+
159+
test_done
160+

0 commit comments

Comments
 (0)