1
- Git User's Manual (for version 1.5.3 or newer)
2
- ______________________________________________
3
-
1
+ Git User Manual
2
+ _______________
4
3
5
4
Git is a fast distributed revision control system.
6
5
@@ -220,7 +219,7 @@ of development leading to that point.
220
219
221
220
The best way to see how this works is using the linkgit:gitk[1]
222
221
command; 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.
224
223
225
224
In the following, we say that commit X is "reachable" from commit Y
226
225
if 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
269
268
a summary of the commands:
270
269
271
270
`git branch`::
272
- list all branches
271
+ list all branches.
273
272
`git branch <branch>`::
274
273
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.
276
275
`git branch <branch> <start-point>`::
277
276
create a new branch named `<branch>`, referencing
278
277
`<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.
280
279
`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.
284
283
`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.
290
285
`git checkout <branch>`::
291
286
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>`.
293
288
`git checkout -b <new> <start-point>`::
294
289
create a new branch `<new>` referencing `<start-point>`, and
295
290
check it out.
@@ -313,10 +308,17 @@ referenced by a tag:
313
308
314
309
------------------------------------------------
315
310
$ 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
+
320
322
HEAD is now at 427abfa... Linux v2.6.17
321
323
------------------------------------------------
322
324
@@ -327,7 +329,7 @@ and git branch shows that you are no longer on a branch:
327
329
$ cat .git/HEAD
328
330
427abfa28afedffadfca9dd8b067eb6d36bac53f
329
331
$ git branch
330
- * (no branch )
332
+ * (detached from v2.6.17 )
331
333
master
332
334
------------------------------------------------
333
335
@@ -787,7 +789,7 @@ e05db0fd4f31dde7005f075a84f96b360d05984b
787
789
-------------------------------------------------
788
790
789
791
Or 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
791
793
both; so
792
794
793
795
-------------------------------------------------
@@ -814,7 +816,7 @@ You could just visually inspect the commits since e05db0fd:
814
816
$ gitk e05db0fd..
815
817
-------------------------------------------------
816
818
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
818
820
name based on any tag it finds pointing to one of the commit's
819
821
descendants:
820
822
@@ -858,8 +860,8 @@ because it outputs only commits that are not reachable from v1.5.0-rc1.
858
860
859
861
As yet another alternative, the linkgit:git-show-branch[1] command lists
860
862
the 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
863
865
864
866
-------------------------------------------------
865
867
$ git show-branch e05db0fd v1.5.0-rc0 v1.5.0-rc1 v1.5.0-rc2
@@ -871,15 +873,15 @@ available
871
873
...
872
874
-------------------------------------------------
873
875
874
- then search for a line that looks like
876
+ then a line like
875
877
876
878
-------------------------------------------------
877
879
+ ++ [e05db0fd] Fix warnings in sha1_file.c - use C99 printf format if
878
880
available
879
881
-------------------------------------------------
880
882
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.
883
885
884
886
[[showing-commits-unique-to-a-branch]]
885
887
Showing commits unique to a given branch
@@ -1074,19 +1076,13 @@ produce no output at that point.
1074
1076
1075
1077
Modifying the index is easy:
1076
1078
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
1084
1080
1085
1081
-------------------------------------------------
1086
1082
$ git add path/to/file
1087
1083
-------------------------------------------------
1088
1084
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
1090
1086
1091
1087
-------------------------------------------------
1092
1088
$ git rm path/to/file
@@ -1787,7 +1783,7 @@ $ git pull . branch
1787
1783
$ git merge branch
1788
1784
-------------------------------------------------
1789
1785
1790
- are roughly equivalent. The former is actually very commonly used.
1786
+ are roughly equivalent.
1791
1787
1792
1788
[[submitting-patches]]
1793
1789
Submitting patches to a project
@@ -2249,11 +2245,11 @@ commit to this branch.
2249
2245
$ ... patch ... test ... commit [ ... patch ... test ... commit ]*
2250
2246
-------------------------------------------------
2251
2247
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
2253
2249
"test" branch in preparation to make it public:
2254
2250
2255
2251
-------------------------------------------------
2256
- $ git checkout test && git pull . speed-up-spinlocks
2252
+ $ git checkout test && git merge speed-up-spinlocks
2257
2253
-------------------------------------------------
2258
2254
2259
2255
It 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
2265
2261
means that the patches can be moved into the `release` tree in any order.
2266
2262
2267
2263
-------------------------------------------------
2268
- $ git checkout release && git pull . speed-up-spinlocks
2264
+ $ git checkout release && git merge speed-up-spinlocks
2269
2265
-------------------------------------------------
2270
2266
2271
2267
After 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:
3197
3193
3198
3194
------------------------------------------------
3199
3195
$ 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)
3208
3201
------------------------------------------------
3209
3202
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
3211
3205
3212
3206
------------------------------------------------
3213
3207
$ git prune
@@ -3305,17 +3299,11 @@ state, you can just prune all unreachable objects:
3305
3299
$ git prune
3306
3300
------------------------------------------------
3307
3301
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
3309
3303
repository--it's kind of like doing a filesystem fsck recovery: you
3310
3304
don'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.)
3319
3307
3320
3308
[[recovering-from-repository-corruption]]
3321
3309
Recovering from repository corruption
@@ -3538,7 +3526,7 @@ with Git 1.5.2 can look up the submodule commits in the repository and
3538
3526
manually check them out; earlier versions won't recognize the submodules at
3539
3527
all.
3540
3528
3541
- To see how submodule support works, create (for example) four example
3529
+ To see how submodule support works, create four example
3542
3530
repositories that can be used later as a submodule:
3543
3531
3544
3532
-------------------------------------------------
@@ -3640,7 +3628,7 @@ working on a branch.
3640
3628
3641
3629
-------------------------------------------------
3642
3630
$ git branch
3643
- * (no branch )
3631
+ * (detached from d266b98 )
3644
3632
master
3645
3633
-------------------------------------------------
3646
3634
@@ -3910,7 +3898,7 @@ fact that such a commit brings together ("merges") two or more
3910
3898
previous states represented by other commits.
3911
3899
3912
3900
In 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,
3914
3902
and explains how we got there.
3915
3903
3916
3904
You 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
3930
3918
result to the file pointed at by `.git/HEAD`, so that we can always see
3931
3919
what the last committed state was.
3932
3920
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:
3935
3922
3936
3923
------------
3937
3924
@@ -4010,27 +3997,26 @@ to see what the top commit was.
4010
3997
Merging multiple trees
4011
3998
----------------------
4012
3999
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.
4018
4005
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.
4023
4009
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:
4026
4012
4027
4013
-------------------------------------------------
4028
4014
$ git merge-base <commit1> <commit2>
4029
4015
-------------------------------------------------
4030
4016
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
4034
4020
4035
4021
-------------------------------------------------
4036
4022
$ 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
4152
4138
that is used to name the object is the hash of the original data
4153
4139
plus this header, so `sha1sum` 'file' does not match the object name
4154
4140
for 'file'.
4155
- (Historical note: in the dawn of the age of Git the hash
4156
- was the SHA-1 of the 'compressed' object.)
4157
4141
4158
4142
As a result, the general consistency of an object can always be tested
4159
4143
independently of the contents or the type of the object: all objects can
0 commit comments