1- Git User's Manual (for version 1.5.3 or newer)
2- ______________________________________________
3-
1+ Git User Manual
2+ _______________
43
54Git is a fast distributed revision control system.
65
@@ -220,7 +219,7 @@ of development leading to that point.
220219
221220The best way to see how this works is using the linkgit:gitk[1]
222221command; running gitk now on a Git repository and looking for merge
223- commits will help understand how the Git organizes history.
222+ commits will help understand how Git organizes history.
224223
225224In the following, we say that commit X is "reachable" from commit Y
226225if commit X is an ancestor of commit Y. Equivalently, you could say
@@ -269,27 +268,23 @@ Creating, deleting, and modifying branches is quick and easy; here's
269268a summary of the commands:
270269
271270`git branch`::
272- list all branches
271+ list all branches.
273272`git branch <branch>`::
274273 create a new branch named `<branch>`, referencing the same
275- point in history as the current branch
274+ point in history as the current branch.
276275`git branch <branch> <start-point>`::
277276 create a new branch named `<branch>`, referencing
278277 `<start-point>`, which may be specified any way you like,
279- including using a branch name or a tag name
278+ including using a branch name or a tag name.
280279`git branch -d <branch>`::
281- delete the branch `<branch>`; if the branch you are deleting
282- points to a commit which is not reachable from the current
283- branch, this command will fail with a warning.
280+ delete the branch `<branch>`; if the branch is not fully
281+ merged in its upstream branch or contained in the current branch,
282+ this command will fail with a warning.
284283`git branch -D <branch>`::
285- even if the branch points to a commit not reachable
286- from the current branch, you may know that that commit
287- is still reachable from some other branch or tag. In that
288- case it is safe to use this command to force Git to delete
289- the branch.
284+ delete the branch `<branch>` irrespective of its merged status.
290285`git checkout <branch>`::
291286 make the current branch `<branch>`, updating the working
292- directory to reflect the version referenced by `<branch>`
287+ directory to reflect the version referenced by `<branch>`.
293288`git checkout -b <new> <start-point>`::
294289 create a new branch `<new>` referencing `<start-point>`, and
295290 check it out.
@@ -313,10 +308,17 @@ referenced by a tag:
313308
314309------------------------------------------------
315310$ git checkout v2.6.17
316- Note: moving to "v2.6.17" which isn't a local branch
317- If you want to create a new branch from this checkout, you may do so
318- (now or later) by using -b with the checkout command again. Example:
319- git checkout -b <new_branch_name>
311+ Note: checking out 'v2.6.17'.
312+
313+ You are in 'detached HEAD' state. You can look around, make experimental
314+ changes and commit them, and you can discard any commits you make in this
315+ state without impacting any branches by performing another checkout.
316+
317+ If you want to create a new branch to retain commits you create, you may
318+ do so (now or later) by using -b with the checkout command again. Example:
319+
320+ git checkout -b new_branch_name
321+
320322HEAD is now at 427abfa... Linux v2.6.17
321323------------------------------------------------
322324
@@ -327,7 +329,7 @@ and git branch shows that you are no longer on a branch:
327329$ cat .git/HEAD
328330427abfa28afedffadfca9dd8b067eb6d36bac53f
329331$ git branch
330- * (no branch )
332+ * (detached from v2.6.17 )
331333 master
332334------------------------------------------------
333335
@@ -787,7 +789,7 @@ e05db0fd4f31dde7005f075a84f96b360d05984b
787789-------------------------------------------------
788790
789791Or you could recall that the `...` operator selects all commits
790- contained reachable from either one reference or the other but not
792+ reachable from either one reference or the other but not
791793both; so
792794
793795-------------------------------------------------
@@ -814,7 +816,7 @@ You could just visually inspect the commits since e05db0fd:
814816$ gitk e05db0fd..
815817-------------------------------------------------
816818
817- Or you can use linkgit:git-name-rev[1], which will give the commit a
819+ or you can use linkgit:git-name-rev[1], which will give the commit a
818820name based on any tag it finds pointing to one of the commit's
819821descendants:
820822
@@ -858,8 +860,8 @@ because it outputs only commits that are not reachable from v1.5.0-rc1.
858860
859861As yet another alternative, the linkgit:git-show-branch[1] command lists
860862the commits reachable from its arguments with a display on the left-hand
861- side that indicates which arguments that commit is reachable from. So,
862- you can run something like
863+ side that indicates which arguments that commit is reachable from.
864+ So, if you run something like
863865
864866-------------------------------------------------
865867$ git show-branch e05db0fd v1.5.0-rc0 v1.5.0-rc1 v1.5.0-rc2
@@ -871,15 +873,15 @@ available
871873...
872874-------------------------------------------------
873875
874- then search for a line that looks like
876+ then a line like
875877
876878-------------------------------------------------
877879+ ++ [e05db0fd] Fix warnings in sha1_file.c - use C99 printf format if
878880available
879881-------------------------------------------------
880882
881- Which shows that e05db0fd is reachable from itself, from v1.5.0-rc1, and
882- from v1.5.0-rc2, but not from v1.5.0-rc0.
883+ shows that e05db0fd is reachable from itself, from v1.5.0-rc1,
884+ and from v1.5.0-rc2, and not from v1.5.0-rc0.
883885
884886[[showing-commits-unique-to-a-branch]]
885887Showing commits unique to a given branch
@@ -1074,19 +1076,13 @@ produce no output at that point.
10741076
10751077Modifying the index is easy:
10761078
1077- To update the index with the new contents of a modified file, use
1078-
1079- -------------------------------------------------
1080- $ git add path/to/file
1081- -------------------------------------------------
1082-
1083- To add the contents of a new file to the index, use
1079+ To update the index with the contents of a new or modified file, use
10841080
10851081-------------------------------------------------
10861082$ git add path/to/file
10871083-------------------------------------------------
10881084
1089- To remove a file from the index and from the working tree,
1085+ To remove a file from the index and from the working tree, use
10901086
10911087-------------------------------------------------
10921088$ git rm path/to/file
@@ -1787,7 +1783,7 @@ $ git pull . branch
17871783$ git merge branch
17881784-------------------------------------------------
17891785
1790- are roughly equivalent. The former is actually very commonly used.
1786+ are roughly equivalent.
17911787
17921788[[submitting-patches]]
17931789Submitting patches to a project
@@ -2249,11 +2245,11 @@ commit to this branch.
22492245$ ... patch ... test ... commit [ ... patch ... test ... commit ]*
22502246-------------------------------------------------
22512247
2252- When you are happy with the state of this change, you can pull it into the
2248+ When you are happy with the state of this change, you can merge it into the
22532249"test" branch in preparation to make it public:
22542250
22552251-------------------------------------------------
2256- $ git checkout test && git pull . speed-up-spinlocks
2252+ $ git checkout test && git merge speed-up-spinlocks
22572253-------------------------------------------------
22582254
22592255It is unlikely that you would have any conflicts here ... but you might if you
@@ -2265,7 +2261,7 @@ see the value of keeping each patch (or patch series) in its own branch. It
22652261means that the patches can be moved into the `release` tree in any order.
22662262
22672263-------------------------------------------------
2268- $ git checkout release && git pull . speed-up-spinlocks
2264+ $ git checkout release && git merge speed-up-spinlocks
22692265-------------------------------------------------
22702266
22712267After a while, you will have a number of branches, and despite the
@@ -3197,17 +3193,15 @@ To put the loose objects into a pack, just run git repack:
31973193
31983194------------------------------------------------
31993195$ git repack
3200- Generating pack...
3201- Done counting 6020 objects.
3202- Deltifying 6020 objects.
3203- 100% (6020/6020) done
3204- Writing 6020 objects.
3205- 100% (6020/6020) done
3206- Total 6020, written 6020 (delta 4070), reused 0 (delta 0)
3207- Pack pack-3e54ad29d5b2e05838c75df582c65257b8d08e1c created.
3196+ Counting objects: 6020, done.
3197+ Delta compression using up to 4 threads.
3198+ Compressing objects: 100% (6020/6020), done.
3199+ Writing objects: 100% (6020/6020), done.
3200+ Total 6020 (delta 4070), reused 0 (delta 0)
32083201------------------------------------------------
32093202
3210- You can then run
3203+ This creates a single "pack file" in .git/objects/pack/
3204+ containing all currently unpacked objects. You can then run
32113205
32123206------------------------------------------------
32133207$ git prune
@@ -3305,17 +3299,11 @@ state, you can just prune all unreachable objects:
33053299$ git prune
33063300------------------------------------------------
33073301
3308- and they'll be gone. But you should only run `git prune` on a quiescent
3302+ and they'll be gone. (You should only run `git prune` on a quiescent
33093303repository--it's kind of like doing a filesystem fsck recovery: you
33103304don't want to do that while the filesystem is mounted.
3311-
3312- (The same is true of `git fsck` itself, btw, but since
3313- `git fsck` never actually *changes* the repository, it just reports
3314- on what it found, `git fsck` itself is never 'dangerous' to run.
3315- Running it while somebody is actually changing the repository can cause
3316- confusing and scary messages, but it won't actually do anything bad. In
3317- contrast, running `git prune` while somebody is actively changing the
3318- repository is a *BAD* idea).
3305+ `git prune` is designed not to cause any harm in such cases of concurrent
3306+ accesses to a repository but you might receive confusing or scary messages.)
33193307
33203308[[recovering-from-repository-corruption]]
33213309Recovering from repository corruption
@@ -3538,7 +3526,7 @@ with Git 1.5.2 can look up the submodule commits in the repository and
35383526manually check them out; earlier versions won't recognize the submodules at
35393527all.
35403528
3541- To see how submodule support works, create (for example) four example
3529+ To see how submodule support works, create four example
35423530repositories that can be used later as a submodule:
35433531
35443532-------------------------------------------------
@@ -3640,7 +3628,7 @@ working on a branch.
36403628
36413629-------------------------------------------------
36423630$ git branch
3643- * (no branch )
3631+ * (detached from d266b98 )
36443632 master
36453633-------------------------------------------------
36463634
@@ -3910,7 +3898,7 @@ fact that such a commit brings together ("merges") two or more
39103898previous states represented by other commits.
39113899
39123900In other words, while a "tree" represents a particular directory state
3913- of a working directory, a "commit" represents that state in " time" ,
3901+ of a working directory, a "commit" represents that state in time,
39143902and explains how we got there.
39153903
39163904You create a commit object by giving it the tree that describes the
@@ -3930,8 +3918,7 @@ save the note about that state, in practice we tend to just write the
39303918result to the file pointed at by `.git/HEAD`, so that we can always see
39313919what the last committed state was.
39323920
3933- Here is an ASCII art by Jon Loeliger that illustrates how
3934- various pieces fit together.
3921+ Here is a picture that illustrates how various pieces fit together:
39353922
39363923------------
39373924
@@ -4010,27 +3997,26 @@ to see what the top commit was.
40103997Merging multiple trees
40113998----------------------
40123999
4013- Git helps you do a three-way merge, which you can expand to n-way by
4014- repeating the merge procedure arbitrary times until you finally
4015- "commit" the state . The normal situation is that you'd only do one
4016- three-way merge ( two parents), and commit it , but if you like to, you
4017- can do multiple parents in one go.
4000+ Git can help you perform a three-way merge, which can in turn be
4001+ used for a many-way merge by repeating the merge procedure several
4002+ times . The usual situation is that you only do one three-way merge
4003+ (reconciling two lines of history) and commit the result , but if
4004+ you like to, you can merge several branches in one go.
40184005
4019- To do a three-way merge, you need the two sets of "commit" objects
4020- that you want to merge, use those to find the closest common parent (a
4021- third "commit" object), and then use those commit objects to find the
4022- state of the directory ("tree" object) at these points.
4006+ To perform a three-way merge, you start with the two commits you
4007+ want to merge, find their closest common parent (a third commit),
4008+ and compare the trees corresponding to these three commits.
40234009
4024- To get the "base" for the merge, you first look up the common parent
4025- of two commits with
4010+ To get the "base" for the merge, look up the common parent of two
4011+ commits:
40264012
40274013-------------------------------------------------
40284014$ git merge-base <commit1> <commit2>
40294015-------------------------------------------------
40304016
4031- which will return you the commit they are both based on. You should
4032- now look up the " tree" objects of those commits, which you can easily
4033- do with (for example)
4017+ This prints the name of a commit they are both based on. You should
4018+ now look up the tree objects of those commits, which you can easily
4019+ do with
40344020
40354021-------------------------------------------------
40364022$ git cat-file commit <commitname> | head -1
@@ -4152,8 +4138,6 @@ about the data in the object. It's worth noting that the SHA-1 hash
41524138that is used to name the object is the hash of the original data
41534139plus this header, so `sha1sum` 'file' does not match the object name
41544140for 'file'.
4155- (Historical note: in the dawn of the age of Git the hash
4156- was the SHA-1 of the 'compressed' object.)
41574141
41584142As a result, the general consistency of an object can always be tested
41594143independently of the contents or the type of the object: all objects can
0 commit comments