49
------------------------------------------------
50
$ mkdir git-tutorial
51
$ cd git-tutorial
52
-$ git-init
52
+$ git init
53
------------------------------------------------
54
55
to which git will reply
149
So to populate the index with the two files you just created, you can do
150
151
------------------------------------------------
152
-$ git-update-index --add hello example
152
+$ git update-index --add hello example
153
------------------------------------------------
154
155
and you have now told git to track those two files.
177
you'll have to use the object name, not the filename of the object:
178
179
----------------
180
-$ git-cat-file -t 557db03de997c86a4a028e1ebd3a1ceb225be238
180
+$ git cat-file -t 557db03de997c86a4a028e1ebd3a1ceb225be238
181
----------------
182
183
where the `-t` tells `git-cat-file` to tell you what the "type" of the
185
regular file), and you can see the contents with
186
187
----------------
188
-$ git-cat-file "blob" 557db03
188
+$ git cat-file "blob" 557db03
189
----------------
190
191
which will print out "Hello World". The object `557db03` is nothing
231
`git-diff-files` command:
232
233
------------
234
-$ git-diff-files
234
+$ git diff-files
235
------------
236
237
Oops. That wasn't very readable. It just spit out its own internal
243
differences as a patch, using the `-p` flag:
244
245
------------
246
-$ git-diff-files -p
246
+$ git diff-files -p
247
diff --git a/hello b/hello
248
index 557db03..263414f 100644
249
--- a/hello
259
what is recorded in the index, and what is currently in the working
260
tree. That's very useful.
261
262
-A common shorthand for `git-diff-files -p` is to just write `git
262
+A common shorthand for `git diff-files -p` is to just write `git
263
diff`, which will do the same thing.
264
265
------------
284
tree was all about, along with information of how we came to that state.
285
286
Creating a tree object is trivial, and is done with `git-write-tree`.
287
-There are no options or other input: git-write-tree will take the
287
+There are no options or other input: git write-tree will take the
288
current index state, and write an object that describes that whole
289
index. In other words, we're now tying together all the different
290
filenames with their contents (and their permissions), and we're
291
creating the equivalent of a git "directory" object:
292
293
------------------------------------------------
294
-$ git-write-tree
294
+$ git write-tree
295
------------------------------------------------
296
297
and this will just output the name of the resulting tree, in this case
302
----------------
303
304
which is another incomprehensible object name. Again, if you want to,
305
-you can use `git-cat-file -t 8988d\...` to see that this time the object
305
+you can use `git cat-file -t 8988d\...` to see that this time the object
306
is not a "blob" object, but a "tree" object (you can also use
307
-`git-cat-file` to actually output the raw object contents, but you'll see
307
+`git cat-file` to actually output the raw object contents, but you'll see
308
mainly a binary mess, so that's less interesting).
309
310
However -- normally you'd never use `git-write-tree` on its own, because
327
all with a sequence of simple shell commands:
328
329
------------------------------------------------
330
-$ tree=$(git-write-tree)
331
-$ commit=$(echo 'Initial commit' | git-commit-tree $tree)
332
-$ git-update-ref HEAD $commit
330
+$ tree=$(git write-tree)
331
+$ commit=$(echo 'Initial commit' | git commit-tree $tree)
332
+$ git update-ref HEAD $commit
333
------------------------------------------------
334
335
In this case this creates a totally new commit that is not related to
356
state in the working tree, and how they don't have to match, even
357
when we commit things.
358
359
-As before, if we do `git-diff-files -p` in our git-tutorial project,
359
+As before, if we do `git diff-files -p` in our git-tutorial project,
360
we'll still see the same difference we saw last time: the index file
361
hasn't changed by the act of committing anything. However, now that we
362
have committed something, we can also learn to use a new command:
372
But now we can do
373
374
----------------
375
-$ git-diff-index -p HEAD
375
+$ git diff-index -p HEAD
376
----------------
377
378
(where `-p` has the same meaning as it did in `git-diff-files`), and it
394
working tree, but when given the `\--cached` flag, it is told to
395
instead compare against just the index cache contents, and ignore the
396
current working tree state entirely. Since we just wrote the index
397
-file to HEAD, doing `git-diff-index \--cached -p HEAD` should thus return
397
+file to HEAD, doing `git diff-index \--cached -p HEAD` should thus return
398
an empty set of differences, and that's exactly what it does.
399
400
[NOTE]
422
update the index cache:
423
424
------------------------------------------------
425
-$ git-update-index hello
425
+$ git update-index hello
426
------------------------------------------------
427
428
(note how we didn't need the `\--add` flag this time, since git knew
429
about the file already).
430
431
Note what happens to the different `git-diff-\*` versions here. After
432
-we've updated `hello` in the index, `git-diff-files -p` now shows no
433
-differences, but `git-diff-index -p HEAD` still *does* show that the
432
+we've updated `hello` in the index, `git diff-files -p` now shows no
433
+differences, but `git diff-index -p HEAD` still *does* show that the
434
current state is different from the state we committed. In fact, now
435
`git-diff-index` shows the same difference whether we use the `--cached`
436
flag or not, since now the index is coherent with the working tree.
477
the same diff that we've already seen several times, we can now do
478
479
----------------
480
-$ git-diff-tree -p HEAD
480
+$ git diff-tree -p HEAD
481
----------------
482
483
(again, `-p` means to show the difference as a human-readable patch),
542
powerful)
543
544
----------------
545
-$ git-whatchanged -p
545
+$ git whatchanged -p
546
----------------
547
548
and you will see exactly what has changed in the repository over its
653
So after you do a `cp -a` to create a new copy, you'll want to do
654
+
655
----------------
656
-$ git-update-index --refresh
656
+$ git update-index --refresh
657
----------------
658
+
659
in the new repository to make sure that the index file is up-to-date.
669
so usually you'll precede the `git-update-index` with a
670
671
----------------
672
-$ git-read-tree --reset HEAD
673
-$ git-update-index --refresh
672
+$ git read-tree --reset HEAD
673
+$ git update-index --refresh
674
----------------
675
676
which will force a total index re-build from the tree pointed to by `HEAD`.
677
It resets the index contents to `HEAD`, and then the `git-update-index`
678
makes sure to match up all index entries with the checked-out files.
679
If the original repository had uncommitted changes in its
680
-working tree, `git-update-index --refresh` notices them and
680
+working tree, `git update-index --refresh` notices them and
681
tells you they need to be updated.
682
683
The above can also be written as simply
690
with the `git xyz` interfaces. You can learn things by just looking
691
at what the various git scripts do. For example, `git reset` used to be
692
the above two lines implemented in `git-reset`, but some things like
693
-`git status` and `git commit` are slightly more complex scripts around
693
+`git-status` and `git-commit` are slightly more complex scripts around
694
the basic git commands.
695
696
Many (most?) public remote repositories will not contain any of
713
followed by
714
715
----------------
716
-$ git-read-tree HEAD
716
+$ git read-tree HEAD
717
----------------
718
719
to populate the index. However, now you have populated the index, and
722
those, you'd check them out with
723
724
----------------
725
-$ git-checkout-index -u -a
725
+$ git checkout-index -u -a
726
----------------
727
728
where the `-u` flag means that you want the checkout to keep the index
839
------------------------------------------------
840
841
Here, we just added another line to `hello`, and we used a shorthand for
842
-doing both `git-update-index hello` and `git commit` by just giving the
842
+doing both `git update-index hello` and `git commit` by just giving the
843
filename directly to `git commit`, with an `-i` flag (it tells
844
git to 'include' that file in addition to what you have done to
845
the index file so far when making the commit). The `-m` flag is to give the
938
environment, is `git show-branch`.
939
940
------------------------------------------------
941
-$ git-show-branch --topo-order --more=1 master mybranch
941
+$ git show-branch --topo-order --more=1 master mybranch
942
* [master] Merge work in mybranch
943
! [mybranch] Some work.
944
--
981
Now, let's pretend you are the one who did all the work in
982
`mybranch`, and the fruit of your hard work has finally been merged
983
to the `master` branch. Let's go back to `mybranch`, and run
984
-`git merge` to get the "upstream changes" back to your branch.
984
+`git-merge` to get the "upstream changes" back to your branch.
985
986
------------
987
$ git checkout mybranch
1198
The command it uses is `git-merge-base`:
1199
1200
------------
1201
-$ mb=$(git-merge-base HEAD mybranch)
1201
+$ mb=$(git merge-base HEAD mybranch)
1202
------------
1203
1204
The command writes the commit object name of the common ancestor
1208
tell it by:
1209
1210
------------
1211
-$ git-name-rev $mb
1211
+$ git name-rev $mb
1212
my-first-tag
1213
------------
1214
1216
this:
1217
1218
------------
1219
-$ git-read-tree -m -u $mb HEAD mybranch
1219
+$ git read-tree -m -u $mb HEAD mybranch
1220
------------
1221
1222
This is the same `git-read-tree` command we have already seen,
1235
inspect the index file with this command:
1236
1237
------------
1238
-$ git-ls-files --stage
1238
+$ git ls-files --stage
1239
100644 7f8b141b65fdcee47321e399a2598a235a032422 0 example
1240
100644 263414f423d0e4d70dae8fe53fa34614ff3e2860 1 hello
1241
100644 06fa6a24256dc7e560efa5687fa84b51f0263c3a 2 hello
1252
To look at only non-zero stages, use `\--unmerged` flag:
1253
1254
------------
1255
-$ git-ls-files --unmerged
1255
+$ git ls-files --unmerged
1256
100644 263414f423d0e4d70dae8fe53fa34614ff3e2860 1 hello
1257
100644 06fa6a24256dc7e560efa5687fa84b51f0263c3a 2 hello
1258
100644 cc44c73eb783565da5831b4d820c962954019b69 3 hello
1264
`git-merge-index` command:
1265
1266
------------
1267
-$ git-merge-index git-merge-one-file hello
1267
+$ git merge-index git-merge-one-file hello
1268
Auto-merging hello.
1269
merge: warning: conflicts during merge
1270
ERROR: Merge conflict in hello.
1282
--stage` again at this point:
1283
1284
------------
1285
-$ git-ls-files --stage
1285
+$ git ls-files --stage
1286
100644 7f8b141b65fdcee47321e399a2598a235a032422 0 example
1287
100644 263414f423d0e4d70dae8fe53fa34614ff3e2860 1 hello
1288
100644 06fa6a24256dc7e560efa5687fa84b51f0263c3a 2 hello
1290
------------
1291
1292
This is the state of the index file and the working file after
1293
-`git merge` returns control back to you, leaving the conflicting
1293
+`git-merge` returns control back to you, leaving the conflicting
1294
merge for you to resolve. Notice that the path `hello` is still
1295
-unmerged, and what you see with `git diff` at this point is
1295
+unmerged, and what you see with `git-diff` at this point is
1296
differences since stage 2 (i.e. your version).
1297
1298
1329
done only once.
1330
1331
[NOTE]
1332
-`git push` uses a pair of programs,
1332
+`git-push` uses a pair of programs,
1333
`git-send-pack` on your local machine, and `git-receive-pack`
1334
on the remote machine. The communication between the two over
1335
the network internally uses an SSH connection.
1349
`.git`, we do things slightly differently:
1350
1351
------------
1352
-$ GIT_DIR=my-git.git git-init
1352
+$ GIT_DIR=my-git.git git init
1353
------------
1354
1355
Make sure this directory is available for others you want your
1368
If you plan to publish this repository to be accessed over http,
1369
you should do `chmod +x my-git.git/hooks/post-update` at this
1370
point. This makes sure that every time you push into this
1371
-repository, `git-update-server-info` is run.
1371
+repository, `git update-server-info` is run.
1372
1373
Your "public repository" is now ready to accept your changes.
1374
Come back to the machine you have your private repository. From
1495
3. Push into the public repository from your primary
1496
repository.
1497
1498
-4. `git repack` the public repository. This establishes a big
1498
+4. `git-repack` the public repository. This establishes a big
1499
pack that contains the initial set of objects as the
1500
- baseline, and possibly `git prune` if the transport
1500
+ baseline, and possibly `git-prune` if the transport
1501
used for pulling from your repository supports packed
1502
repositories.
1503
1511
6. Push your changes to the public repository, and announce it
1512
to the public.
1513
1514
-7. Every once in a while, "git repack" the public repository.
1514
+7. Every once in a while, "git-repack" the public repository.
1515
Go back to step 5. and continue working.
1516
1517
1518
A recommended work cycle for a "subsystem maintainer" who works
1519
on that project and has an own "public repository" goes like this:
1520
1521
-1. Prepare your work repository, by `git clone` the public
1521
+1. Prepare your work repository, by `git-clone` the public
1522
repository of the "project lead". The URL used for the
1523
initial cloning is stored in the remote.origin.url
1524
configuration variable.
1533
point at the repository you are borrowing from.
1534
1535
4. Push into the public repository from your primary
1536
- repository. Run `git repack`, and possibly `git prune` if the
1536
+ repository. Run `git-repack`, and possibly `git-prune` if the
1537
transport used for pulling from your repository supports
1538
packed repositories.
1539
1550
"project lead" and possibly your "sub-subsystem
1551
maintainers" to pull from it.
1552
1553
-7. Every once in a while, `git repack` the public repository.
1553
+7. Every once in a while, `git-repack` the public repository.
1554
Go back to step 5. and continue working.
1555
1556
1558
not have a "public" repository is somewhat different. It goes
1559
like this:
1560
1561
-1. Prepare your work repository, by `git clone` the public
1561
+1. Prepare your work repository, by `git-clone` the public
1562
repository of the "project lead" (or a "subsystem
1563
maintainer", if you work on a subsystem). The URL used for
1564
the initial cloning is stored in the remote.origin.url