public
Description: A guide to using Git
Homepage: http://cs.stanford.edu/~blynn/gitmagic/
Clone URL: git://github.com/blynn/gitmagic.git
Search Repo:
More detail in second chapter

Added outline of other chapters and other helper files
Ben Lynn (author)
Fri Aug 31 02:13:18 -0700 2007
Ben Lynn (committer)
Fri Aug 31 02:13:18 -0700 2007
commit  f32ad24917d6fe0b5fbf2eeed17c1afd66e85b93
tree    ca242496172c305ba5546ecb0ded798fffbea153
parent  b1b11039856d536c1f77c932d6268b11a70c15ce
...
1
 
2
3
 
 
 
4
5
6
 
7
8
9
10
 
11
12
13
...
 
1
2
 
3
4
5
6
7
 
8
9
10
11
12
13
14
15
16
0
@@ -1,13 +1,16 @@
0
-target: book.html
0
+.PHONY: target clean
0
 
0
-TXTFILES=intro.txt basic.txt
0
+target: book book.html
0
+
0
+TXTFILES=intro.txt basic.txt clone.txt branch.txt
0
 
0
 book.xml: $(TXTFILES)
0
- ./bookmake $^ > book.xml
0
+ cat $^ | sed 's/<tt>/<command>/g' | sed 's/<\/tt>/<\/command>/g' | ./bookmake > book.xml
0
 
0
 book: book.xml
0
   xmlto -m custom-html.xsl -o book html book.xml
0
   -ls book/*.html | xargs -n 1 tidy -utf8 -m -i -q
0
+ ./makeover
0
 
0
 book.html: book.xml
0
   xmlto -m custom-nochunks.xsl html-nochunks $^
...
1
 
 
 
2
3
4
...
6
7
8
9
 
10
11
12
13
14
15
16
 
17
18
 
19
20
 
21
22
 
23
24
 
25
26
 
27
28
 
29
30
31
 
32
33
 
34
35
 
36
37
 
38
39
 
40
41
42
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
45
 
46
47
 
48
49
 
50
51
52
...
 
1
2
3
4
5
6
...
8
9
10
 
11
12
13
14
15
 
 
 
16
17
 
18
19
 
20
21
 
22
23
 
24
25
 
26
27
 
28
29
 
 
30
31
 
32
33
 
34
35
 
36
37
 
38
39
40
41
 
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 
64
65
 
66
67
 
68
69
70
71
0
@@ -1,4 +1,6 @@
0
-= Basic Git Tricks =
0
+= Basic Tricks =
0
+
0
+Rather than diving into a sea of Git commands, use these elementary examples to get your feet wet. Despite their simplicity, each of them are useful in real life.
0
 
0
 == Instant Backup ==
0
 
0
@@ -6,47 +8,64 @@ When I'm about to attempt something drastic I like to save the current state, so
0
 
0
  $ git-init
0
  $ git-add .
0
- $ git-commit -m "Initial commit"
0
+ $ git-commit -m "my first backup"
0
 
0
 to take a snapshot of all files in the current directory.
0
 Then if something goes wrong type
0
 
0
- $ git-reset --hard
0
-
0
-to go back to where you were. To save the state again, type <command>git-commit -a</command> and provide a description.
0
+ $ git-checkout HEAD .
0
 
0
-One benefit to doing this instead of simply copying files is that with Git's hash chaining, you can tell if a backup gets corrupted.
0
+to go back to where you were. To save the state again, you can type
0
 
0
-== Undo/Redo History ==
0
+ $ git-commit -a -m "another backup"
0
 
0
-More generally, you can do the above, and every so often "save the game" by typing
0
+=== Adding, Deleting, Renaming Files ===
0
 
0
- $ git-commit -a -m "description of current state"
0
+The above will only keep track of the files that were present when you first ran <tt>git-add</tt>. If you add new files to the directory, you'll have to tell Git:
0
 
0
-Note if you want to keep track of newly added files or forget about deleted files you'll need to first run <command>git-add</command> or <command>git-delete</command> accordingly.
0
+ $ git-add NEWFILES...
0
 
0
-Typing git-log shows you a list of recent commits, and their SHA1 hashes. Then typing
0
+Similarly, if you want Git to forget about certain files, maybe because you've deleted them
0
 
0
- $ git-commit -a
0
- $ git-revert SHA1_HASH
0
+ $ git-rm OLDFILES...
0
 
0
-will restore the state to the commit with the given hash. You might like to use something like the following instead:
0
+Renaming a file is the same as removing the old name and adding the new name. There's also the shortcut <tt>git-mv</tt> which has the same syntax as the <tt>mv</tt> command. For example:
0
 
0
- $ git-revert "@{10 minutes ago}"
0
+ $ git-mv OLDFILE NEWFILE
0
 
0
-You can undo the undo: type git-log and you'll see that the other commits you made are still there.
0
+== Advanced Undo/Redo ==
0
 
0
-Typing
0
+Typing <tt>git-log</tt> shows you a list of recent commits, and their SHA1 hashes. Then typing:
0
 
0
  $ git-checkout SHA1_HASH .
0
 
0
-loads a saved state without recording the fact that you've gone back to an old state. This is sometimes what you want.
0
+will load the previous state with the given hash.
0
+Don't like working with hashes? Then use:
0
+
0
+ $ git-checkout "@{10 minutes ago}" .
0
+
0
+Other time specifications work too. Or you can ask for the 5th-last saved state:
0
+
0
+ $ git-checkout "@{5}" .
0
+
0
+In some circumstances, it is preferable to type:
0
+
0
+ $ git-commit -a
0
+ $ git-revert SHA1_HASH
0
+
0
+This appears to have the same affect, but <tt>git-log</tt> reveals that the fact that you loaded an old saved state has been recorded as new commit. In other words, you can have Git track you when you undo and redo.
0
+
0
+Lastly, other times you might want:
0
+
0
+ $ git-reset --hard SHA1_HASH
0
+
0
+which restores the state to a given commit but also erases all newer commits from the record permanently.
0
 
0
-To take the computer game analogy again, git-checkout is like loading a game, git-revert is like loading a game and recording this fact as another saved game, and git-reset --hard is like loading an old save and deleting all saved games newer than the one just loaded.
0
+To take the computer game analogy again, <tt>git-checkout</tt> is like loading a game, <tt>git-revert</tt> is like loading a game and recording this fact as another saved game, and <tt>git-reset --hard</tt> is like loading an old save and deleting all saved games newer than the one just loaded.
0
 
0
-== Synchronize Files Between Computers ==
0
+== Sync Computers ==
0
 
0
-This is the reason I first used Git. I can make tarballs or use rsync to do backups. The problem was sometimes I'd edit on my laptop, other times on my desktop, and they may not have talked to each other in between.
0
+This is the reason I first used Git. I can tolerate making tarballs or using <tt>rsync</tt> for backups. The problem was sometimes I'd edit on my laptop, other times on my desktop, and they may not have talked to each other in between.
0
 
0
 Initialize a Git repository and commit your files as above on one machine. Then on the other:
0
 
...
10
11
12
13
14
15
 
 
 
 
 
 
 
 
16
...
10
11
12
 
 
 
13
14
15
16
17
18
19
20
21
0
@@ -10,7 +10,12 @@ echo '<?xml version="1.0" encoding="utf-8"?>
0
     <copyright><year>2007</year><holder>Ben Lynn</holder></copyright>
0
 </bookinfo>'
0
 
0
-for FILE in $*; do
0
- ./wiki2xml $FILE
0
-done
0
+if [ $# -gt 0 ]; then
0
+ for FILE in $*; do
0
+ ./wiki2xml $FILE
0
+ done
0
+else
0
+ ./wiki2xml
0
+fi
0
+
0
 echo '</book>'
...
1
 
2
3
4
5
6
7
8
 
9
10
11
12
 
13
14
15
16
 
17
18
 
19
20
21
...
29
30
31
32
 
33
34
 
35
36
 
37
38
 
39
40
41
...
 
1
2
3
4
5
6
7
 
8
9
10
11
 
12
13
14
15
 
16
17
 
18
19
20
21
...
29
30
31
 
32
33
 
34
35
 
36
37
 
38
39
40
41
0
@@ -1,21 +1,21 @@
0
-= Introduction to Version Control =
0
+= Introduction =
0
 
0
 I'll use an analogy to introduce version control, also termed revision control, source control, or source code management.
0
 See [[http://en.wikipedia.org/wiki/Revision_control][the Wikipedia entry on revision control]] for a normal explanation.
0
 
0
 == Work is Play ==
0
 
0
-I've played computer games almost all my life. In contrast only started using version control systems as an adult. Not surprisingly, I'm a lot more familiar with video game concepts than version control ones. I'm certain I'm not alone.
0
+I've played computer games almost all my life. In contrast I only started using version control systems as an adult. I suspect I'm not alone, and comparing the two may make version control easier to explain and understand.
0
 
0
 Think of editing your document, or your code, or whatever, as playing a game. Once you've made a lot of progress, you'd like to save. To do so, you click on the "Save" button in your trusty editor.
0
 
0
-But this will overwrite the old version. It's like those old school games which only had one save slot: sure you could save, but you could never go back to an older state. Which was a shame, because your previous save might have been right at a really fun part of the game that you'd like to revisit one day.
0
+But this will overwrite the old version. It's like those old school games which only had one save slot: sure you could save, but you could never go back to an older state. Which was a shame, because your previous save might have been right at a really fun part of the game that you'd like to revisit one day. Or worse still, your current save is in an unwinnable state, which means you have to start again.
0
 
0
 == Version Control ==
0
 
0
-You can "Save As..." a different file, or copy the old one somewhere first before saving if you want to savour old versions. Maybe compress them too to save space. We have just described a primitive labour-intensive form of version control.
0
+When editing, you can "Save As..." a different file, or copy the file somewhere first before saving if you want to savour old versions. Maybe compress them too to save space. This is version control, but very primitive and labour-intensive.
0
 
0
-Let's make the problem slightly tougher now. Say you have a bunch of files that go together, such as collection of source code for the same project, or files for a website. Now if you want to keep an old version you have to copy a whole directory of stuff. Keeping many versions around is inconvenient to do by hand.
0
+Let's make the problem slightly tougher now. Say you have a bunch of files that go together, such as collection of source code for the same project, or files for a website. Now if you want to keep an old version you have to archive a whole directory of stuff. Keeping many versions around is inconvenient to do by hand, and gets expensive fast.
0
 
0
 In some computer games, saving the game actually writes a directory full of files. They hide these details from the player and present a convenient interface for you to manage saves.
0
 
0
@@ -29,13 +29,13 @@ How would you set up a system so they can get at each other's saves easily? And
0
 
0
 In the old days, every project used centralized version control. A server somewhere held all the saved games. Nobody else did. Every player kept at most a few saved games on their machine. When a player wanted to make progress, they'd download the latest save from the main server, play a while, save and upload back to the server for everyone else to use.
0
 
0
-What if a player wanted to get an older saved game for any reason? Maybe the current saved game is in an unfinishable state because somebody forgot to pick up an object back in level three, and they want to find the latest saved game where the game still can completed. Or maybe they want to compare two older saved games to see how much work a particular player did.
0
+What if a player wanted to get an older saved game for some reason? Maybe the current saved game is in an unwinnable state because somebody forgot to pick up an object back in level three, and they want to find the latest saved game where the game can still be completed. Or maybe they want to compare two older saved games to see how much work a particular player did.
0
 
0
-There could be many reasons to want to see an older revision, but the outcome is the same. They have to ask the central server for that old save. The more saves they want, the more communication that is required.
0
+There could be many reasons to want to see an older revision, but the outcome is the same. They have to ask the central server for that old saved game. The more saved games they want, the more communication that is required.
0
 
0
-The new generation of version control systems, to which Git belong, are known as distributed systems, and can be thought of as a generalization of the centralized systems. When players download from the main server they get every saved game, not just the latest one. It's as if they're mirroring the central server.
0
+The new generation of version control systems, of which Git is a member, are known as distributed systems, and can be thought of as a generalization of centralized systems. When players download from the main server they get every saved game, not just the latest one. It's as if they're mirroring the central server.
0
 
0
-One immediately obvious benefit is that when an old save is desired for any reason, communication with the central server is unnecessary.
0
+Thus the initial cloning can be expensive, especially if there's a long history, but it pays off in the long run. One immediately obvious benefit is that when an old save is desired for any reason, communication with the central server is unnecessary.
0
 
0
 == Merge Conflicts ==
0
 
...
15
16
17
 
18
19
20
...
37
38
39
40
41
42
43
...
45
46
47
 
 
 
 
 
 
 
 
48
49
50
...
55
56
57
 
 
58
59
60
...
79
80
81
82
83
84
 
85
...
15
16
17
18
19
20
21
...
38
39
40
 
41
42
43
...
45
46
47
48
49
50
51
52
53
54
55
56
57
58
...
63
64
65
66
67
68
69
70
...
89
90
91
 
 
 
92
93
0
@@ -15,6 +15,7 @@ func close_section() {
0
 }
0
 
0
 func close_until(i) {
0
+ close_block()
0
     while (stack_i > i) {
0
   close_section()
0
     }
0
@@ -37,7 +38,6 @@ func in_block(s) {
0
 
0
 BEGIN {
0
     stack_i = 0
0
- open_section("chapter")
0
 }
0
 
0
 /^ *$/ {
0
@@ -45,6 +45,14 @@ BEGIN {
0
     next
0
 }
0
 
0
+/^ *===.*===$/ {
0
+ gsub(" *=== *","")
0
+ close_until(2)
0
+ open_section("section")
0
+ print "<title>"$0"</title>"
0
+ next
0
+}
0
+
0
 /^ *==.*==$/ {
0
     gsub(" *== *","")
0
     close_until(1)
0
@@ -55,6 +63,8 @@ BEGIN {
0
 
0
 /^ *=.*=$/ {
0
     gsub(" *= *","")
0
+ close_until(0)
0
+ open_section("chapter")
0
     print "<title>"$0"</title>"
0
     next
0
 }
0
@@ -79,7 +89,5 @@ BEGIN {
0
 }
0
 
0
 END {
0
- while (stack_i > 0) {
0
- close_section()
0
- }
0
+ close_until(0)
0
 }

Comments

    No one has commented yet.