public
Description: A guide to using Git
Homepage: http://cs.stanford.edu/~blynn/gitmagic/
Clone URL: git://github.com/blynn/gitmagic.git
Intro edits.
blynn (author)
Tue May 20 00:40:09 -0700 2008
commit  3f5de7128f9fd8c5d45d42bc24fc0f993f7da0e1
tree    61bf0d7860621129c0c83eaebfaa0df6ff6600d1
parent  fc9fac27489bc4006b306e20e2e437cc4a37bd29
...
6
7
8
 
 
9
10
11
12
13
14
15
16
17
...
62
63
64
65
 
66
67
68
...
6
7
8
9
10
11
12
13
14
 
 
15
16
17
...
62
63
64
 
65
66
67
68
0
@@ -6,12 +6,12 @@ Rather than diving into a sea of Git commands, use these elementary examples to
0
 
0
 When I'm about to attempt something drastic I like to save the current state, so I can go back and try again should things go awry.
0
 
0
+Take a snapshot of all files in the current directory with:
0
+
0
  $ git init
0
  $ git add .
0
  $ git commit -m "My first backup"
0
 
0
-to take a snapshot of all files in the current directory.
0
-
0
 The above sequence of commands should be memorized, or placed in a script, as they will be reused frequently.
0
 
0
 Then if something goes wrong, run:
0
@@ -62,7 +62,7 @@ This alternate reality is called a ''branch'', and <<branch,we'll have more to s
0
 
0
 will take you back to the present.
0
 
0
-Note uncommitted changes will travel in time with you when you use the checkout command.
0
+Uncommitted changes travel in time with you when you run checkout.
0
 
0
 To take the computer game analogy again:
0
 
...
40
41
42
43
 
44
45
46
...
69
70
71
72
 
73
74
75
...
40
41
42
 
43
44
45
46
...
69
70
71
 
72
73
74
75
0
@@ -40,7 +40,7 @@ Initialize a Git repository for your files:
0
 On the central server, initialize an empty Git repository with some name,
0
 and start the Git daemon if necessary:
0
 
0
- $ GIT_DIR==proj.git git init
0
+ $ GIT_DIR=proj.git git init
0
  $ git daemon --detach # it might already be running
0
 
0
 Some public hosts, such as http://repo.or.cz[repo.or.cz], will have a different method for setting up the initially empty Git repository, such as filling in a form on a webpage.
0
@@ -69,7 +69,7 @@ Sick of the way a project is being run? Think you could do a better job? Then on
0
 
0
  $ git clone git://main.server/path/to/files
0
 
0
-Next tell everyone to check out your fork of the project at your server.
0
+Next tell everyone about your fork of the project at your server.
0
 
0
 At any later time, you can merge in the changes from the original project with:
0
 
...
61
62
63
64
 
65
66
67
...
131
132
133
134
 
135
136
137
138
139
140
 
141
142
143
...
61
62
63
 
64
65
66
67
...
131
132
133
 
134
135
136
137
138
139
 
140
141
142
143
0
@@ -61,7 +61,7 @@ Did you just commit, but wish you had typed a different message? Realized you fo
0
 
0
 can help you out.
0
 
0
-Since this changes the history, only do this if you have yet to push your changes, otherwise your tree will diverge from other trees. Of course, if you control all the other trees too, then there is no problem since you can always overwrite them.
0
+Since this changes the history, only do this if you have yet to push your changes, otherwise your tree will diverge from other trees. Of course, if you control all the other trees too, then there is no problem since you can overwrite them.
0
 
0
 === ... And Then Some ===
0
 
0
@@ -131,13 +131,13 @@ But suppose you never took it down? Don't worry, for commands like these, Git sa
0
 
0
 Perhaps ORIG_HEAD isn't enough. Perhaps you've just realized you made a monumental mistake last month and you need to go back to an ancient commit in a long-forgotten branch.
0
 
0
-It's hard to lose Git commits permanently, even after deleting branches. As long as you never run git gc, your commits are preserved forever and can be restored at any time.
0
+It's hard to lose Git commits permanently, even after deleting branches. As long as you never run *git gc \--prune*, your commits are preserved forever and can be restored at any time.
0
 
0
 The trouble is finding the appropriate hash. You could look at all the hash values in `.git/objects` and use trial and error to find the one you want. But there's a much easier way.
0
 
0
 Git records every hash of a commit it computes in `.git/logs`. The subdirectory `refs` contains the history of all activity on all branches, while the file `HEAD` shows every hash value it has ever taken. The latter can be used to find hashes of commits on branches that have been accidentally lopped off.
0
 
0
-Eventually, you may want to run git gc to recover space. Be aware that doing so prevents you from recovering lost HEADs.
0
+Eventually, you may want to run *git gc \--prune* to recover space. Be aware that doing so prevents you from recovering lost HEADs.
0
 
0
 === Building On Git ===
0
 
...
38
39
40
41
 
42
43
 
44
45
 
46
47
48
49
50
51
 
52
53
 
 
 
 
 
...
38
39
40
 
41
42
 
43
44
 
45
46
47
48
49
50
 
51
52
 
53
54
55
56
57
0
@@ -38,16 +38,20 @@ This initial cloning operation can be expensive, especially if there's a long hi
0
 
0
 ==== A Silly Superstition ====
0
 
0
-A popular misconception is that distributed systems are ill-suited for projects requiring an official central repository (see for example http://www.subversionary.org/martintomes/git[this blog post]). Nothing could be further from the truth. Photographing someone does not cause their soul to be stolen. Similarly, cloning the master repository does not diminish its importance.
0
+A popular misconception is that distributed systems are ill-suited for projects requiring an official central repository. Nothing could be further from the truth. Photographing someone does not cause their soul to be stolen. Similarly, cloning the master repository does not diminish its importance.
0
 
0
-A good first approximation is that anything a centralized version control system can do, a well-designed distributed system can do better. While not strictly true, one is less likely to make erroneous comparisons with this rule of thumb.
0
+A good first approximation is that anything a centralized version control system can do, a well-designed distributed system can do better. Network resources are simply costlier than local resources. While we shall later see there are drawbacks to a distributed approach, one is less likely to make erroneous comparisons with this rule of thumb.
0
 
0
-You might not use most features of such a system in a small project, but there is nothing wrong with this as there is negligible overhead. Moreover, your project may grow beyond your original expectations. It's like carrying a Swiss army knife even though you mostly use it to open bottles. On the day you desperately need a screwdriver you'll be glad you haven't been carrying a plain bottle-opener all this time.
0
+A small project may only need a fraction of the features offered by such a system. But would you use Roman numerals when calculating with small numbers? Moreover, your project may grow beyond your original expectations. Using Git from the outset is like carrying a Swiss army knife even though you mostly use it to open bottles. On the day you desperately need a screwdriver you'll be glad you have more than a plain bottle-opener.
0
 
0
 === Merge Conflicts ===
0
 
0
 An interesting problem arises in any type of revision control system. Suppose Alice and Bob have both independently downloaded the latest saved game. They both play the game a bit more and save. What if they both want to submit their new saves? Let's say Alice uploads first. Then when Bob tries to upload his save, the system realizes that his state does not chronologically follow Alice's state.
0
 
0
-Ideally, the team possesses some sort of tool that can merge together progress from two different saved games into a new saved game. With such a tool, the problem is solved because Bob can merge Alice's state into his, and then upload the result. But in general, there is no such tool that can handle all cases and sometimes the only solution is human intervention.
0
+Let us revert to editing a text file. Our computer game analogy becomes too thinly stretched since most games never worry about this.
0
 
0
-Many revision control systems can automatically sort out simple merge conflicts with text files, and will ask a human to help if they cannot resolve the problem themselves.
0
+So suppose Alice has inserted a line at the beginning of a file, and Bob appends one at the end. They both upload their changes. Most systems will automatically deduce a reasonable course of action: accept and merge their changes, so both Alice's and Bob's edits are applied.
0
+
0
+Now suppose both Alice and Bob have both made distinct edits to the same line. Then it is impossible to resolve the conflict without human intervention. The second person to upload is informed of a merge conflict, and they must either choose one edit over another, or revise the line entirely.
0
+
0
+More complex situations can arise. Version control systems handle the simpler cases themselves, and leave the difficult cases for humans. Usually their behaviour is configurable.

Comments

    No one has commented yet.