зеркало из https://github.com/microsoft/git.git
Documentation: more examples.
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Родитель
180c474647
Коммит
1e2ccd3abc
|
@ -50,6 +50,35 @@ Everybody uses these commands to feed and care git repositories.
|
||||||
|
|
||||||
* gitlink:git-repack[1] to pack loose objects for efficiency.
|
* gitlink:git-repack[1] to pack loose objects for efficiency.
|
||||||
|
|
||||||
|
Examples
|
||||||
|
~~~~~~~~
|
||||||
|
|
||||||
|
Check health and remove cruft::
|
||||||
|
+
|
||||||
|
------------
|
||||||
|
$ git fsck-objects <1>
|
||||||
|
$ git prune
|
||||||
|
$ git count-objects <2>
|
||||||
|
$ git repack <3>
|
||||||
|
$ git prune <4>
|
||||||
|
|
||||||
|
<1> running without "--full" is usually cheap and assures the
|
||||||
|
repository health reasonably well.
|
||||||
|
<2> check how many loose objects there are and how much
|
||||||
|
diskspace is wasted by not repacking.
|
||||||
|
<3> without "-a" repacks incrementally. repacking every 4-5MB
|
||||||
|
of loose objects accumulation may be a good rule of thumb.
|
||||||
|
<4> after repack, prune removes the duplicate loose objects.
|
||||||
|
------------
|
||||||
|
|
||||||
|
Repack a small project into single pack::
|
||||||
|
+
|
||||||
|
------------
|
||||||
|
$ git repack -a -d <1>
|
||||||
|
$ git prune
|
||||||
|
------------
|
||||||
|
|
||||||
|
|
||||||
Individual Developer (Standalone)[[Individual Developer (Standalone)]]
|
Individual Developer (Standalone)[[Individual Developer (Standalone)]]
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -88,7 +117,8 @@ following commands.
|
||||||
Examples
|
Examples
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
|
|
||||||
* Extract a tarball and create a working tree and a new repository to keep track of it.
|
Extract a tarball and create a working tree and a new repository to keep track of it::
|
||||||
|
+
|
||||||
------------
|
------------
|
||||||
$ tar zxf frotz.tar.gz
|
$ tar zxf frotz.tar.gz
|
||||||
$ cd frotz
|
$ cd frotz
|
||||||
|
@ -101,7 +131,8 @@ $ git tag v2.43 <2>
|
||||||
<2> make a lightweight, unannotated tag.
|
<2> make a lightweight, unannotated tag.
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* Create a topic branch and develop
|
Create a topic branch and develop::
|
||||||
|
+
|
||||||
------------
|
------------
|
||||||
$ git checkout -b alsa-audio <1>
|
$ git checkout -b alsa-audio <1>
|
||||||
$ edit/compile/test
|
$ edit/compile/test
|
||||||
|
@ -158,12 +189,13 @@ addition to the ones needed by a standalone developer.
|
||||||
Examples
|
Examples
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
|
|
||||||
* Clone the upstream and work on it. Feed changes to upstream.
|
Clone the upstream and work on it. Feed changes to upstream::
|
||||||
|
+
|
||||||
------------
|
------------
|
||||||
$ git clone git://git.kernel.org/pub/scm/.../torvalds/linux-2.6 my2.6
|
$ git clone git://git.kernel.org/pub/scm/.../torvalds/linux-2.6 my2.6
|
||||||
$ cd my2.6
|
$ cd my2.6
|
||||||
$ edit/compile/test; git commit -a -s <1>
|
$ edit/compile/test; git commit -a -s <1>
|
||||||
$ git format-patch master <2>
|
$ git format-patch origin <2>
|
||||||
$ git pull <3>
|
$ git pull <3>
|
||||||
$ git whatchanged -p ORIG_HEAD.. arch/i386 include/asm-i386 <4>
|
$ git whatchanged -p ORIG_HEAD.. arch/i386 include/asm-i386 <4>
|
||||||
$ git pull git://git.kernel.org/pub/.../jgarzik/libata-dev.git ALL <5>
|
$ git pull git://git.kernel.org/pub/.../jgarzik/libata-dev.git ALL <5>
|
||||||
|
@ -180,7 +212,8 @@ area we are interested in.
|
||||||
<7> garbage collect leftover objects from reverted pull.
|
<7> garbage collect leftover objects from reverted pull.
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* Branch off of a specific tag.
|
Branch off of a specific tag::
|
||||||
|
+
|
||||||
------------
|
------------
|
||||||
$ git checkout -b private2.6.14 v2.6.14 <1>
|
$ git checkout -b private2.6.14 v2.6.14 <1>
|
||||||
$ edit/compile/test; git commit -a
|
$ edit/compile/test; git commit -a
|
||||||
|
@ -219,7 +252,8 @@ commands in addition to the ones needed by participants.
|
||||||
Examples
|
Examples
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
|
|
||||||
* My typical GIT day.
|
My typical GIT day::
|
||||||
|
+
|
||||||
------------
|
------------
|
||||||
$ git status <1>
|
$ git status <1>
|
||||||
$ git show-branch <2>
|
$ git show-branch <2>
|
||||||
|
@ -231,16 +265,17 @@ $ git checkout master
|
||||||
$ git am -3 -i -s -u ./+to-apply <4>
|
$ git am -3 -i -s -u ./+to-apply <4>
|
||||||
$ compile/test
|
$ compile/test
|
||||||
$ git checkout -b hold/linus && git am -3 -i -s -u ./+hold-linus <5>
|
$ git checkout -b hold/linus && git am -3 -i -s -u ./+hold-linus <5>
|
||||||
$ git checkout pu && git reset --hard master <6>
|
$ git checkout topic/one && git rebase master <6>
|
||||||
$ git pull . topic/one topic/two && git pull . hold/linus <7>
|
$ git checkout pu && git reset --hard master <7>
|
||||||
|
$ git pull . topic/one topic/two && git pull . hold/linus <8>
|
||||||
$ git fetch ko master:refs/tags/ko-master &&
|
$ git fetch ko master:refs/tags/ko-master &&
|
||||||
git show-branch master ko-master <8>
|
git show-branch master ko-master <9>
|
||||||
$ git push ko <9>
|
$ git push ko <10>
|
||||||
$ git checkout maint
|
$ git checkout maint
|
||||||
$ git cherry-pick master~4 <10>
|
$ git cherry-pick master~4 <11>
|
||||||
$ compile/test
|
$ compile/test
|
||||||
$ git tag -s -m 'GIT 0.99.9x' v0.99.9x <11>
|
$ git tag -s -m 'GIT 0.99.9x' v0.99.9x <12>
|
||||||
$ git push ko v0.99.9x <12>
|
$ git push ko v0.99.9x <13>
|
||||||
|
|
||||||
<1> see what I was in the middle of doing, if any.
|
<1> see what I was in the middle of doing, if any.
|
||||||
<2> see what topic branches I have and think about how ready
|
<2> see what topic branches I have and think about how ready
|
||||||
|
@ -250,14 +285,16 @@ that are not quite ready.
|
||||||
<4> apply them, interactively, with my sign-offs.
|
<4> apply them, interactively, with my sign-offs.
|
||||||
<5> create topic branch as needed and apply, again with my
|
<5> create topic branch as needed and apply, again with my
|
||||||
sign-offs.
|
sign-offs.
|
||||||
<6> restart "pu" every time from the master.
|
<6> rebase internal topic branch that has not been merged to the
|
||||||
<7> and bundle topic branches still cooking.
|
master, nor exposed as a part of a stable branch.
|
||||||
<8> make sure I did not accidentally rewound master beyond what I
|
<7> restart "pu" every time from the master.
|
||||||
|
<8> and bundle topic branches still cooking.
|
||||||
|
<9> make sure I did not accidentally rewound master beyond what I
|
||||||
already pushed out.
|
already pushed out.
|
||||||
<9> push out the bleeding edge.
|
<10> push out the bleeding edge.
|
||||||
<10> backport a critical fix.
|
<11> backport a critical fix.
|
||||||
<11> create a signed tag.
|
<12> create a signed tag.
|
||||||
<12> push the tag out.
|
<13> push the tag out.
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
|
||||||
|
@ -276,3 +313,25 @@ and maintain access to the repository by developers.
|
||||||
* link:howto/update-hook-example.txt[update hook howto] has a
|
* link:howto/update-hook-example.txt[update hook howto] has a
|
||||||
good example of managing a shared central repository.
|
good example of managing a shared central repository.
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
~~~~~~~~
|
||||||
|
|
||||||
|
Run git-daemon to serve /pub/scm from inetd::
|
||||||
|
+
|
||||||
|
------------
|
||||||
|
$ grep git /etc/inet.conf
|
||||||
|
git stream tcp nowait nobody /usr/bin/git-daemon git-daemon --inetd --syslog --export-all /pub/scm
|
||||||
|
------------
|
||||||
|
|
||||||
|
Give push/pull only access to developers::
|
||||||
|
+
|
||||||
|
------------
|
||||||
|
$ grep git /etc/shells
|
||||||
|
/usr/bin/git-shell
|
||||||
|
$ grep git /etc/passwd
|
||||||
|
alice:x:1000:1000::/home/alice:/usr/bin/git-shell
|
||||||
|
bob:x:1001:1001::/home/bob:/usr/bin/git-shell
|
||||||
|
cindy:x:1002:1002::/home/cindy:/usr/bin/git-shell
|
||||||
|
david:x:1003:1003::/home/david:/usr/bin/git-shell
|
||||||
|
------------
|
||||||
|
|
|
@ -69,7 +69,7 @@ recover from this in one of two ways:
|
||||||
|
|
||||||
. hand resolve the conflict in the working directory, and update
|
. hand resolve the conflict in the working directory, and update
|
||||||
the index file to bring it in a state that the patch should
|
the index file to bring it in a state that the patch should
|
||||||
have produced. Then run the command with '--resume' option.
|
have produced. Then run the command with '--resolved' option.
|
||||||
|
|
||||||
The command refuses to process new mailboxes while `.dotest`
|
The command refuses to process new mailboxes while `.dotest`
|
||||||
directory exists, so if you decide to start over from scratch,
|
directory exists, so if you decide to start over from scratch,
|
||||||
|
|
|
@ -32,6 +32,32 @@ start-point::
|
||||||
Where to create the branch; defaults to HEAD. This
|
Where to create the branch; defaults to HEAD. This
|
||||||
option has no meaning with -d and -D.
|
option has no meaning with -d and -D.
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
~~~~~~~~
|
||||||
|
|
||||||
|
Start development off of a know tag::
|
||||||
|
+
|
||||||
|
------------
|
||||||
|
$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
|
||||||
|
$ cd my2.6
|
||||||
|
$ git branch my2.6.14 v2.6.14 <1>
|
||||||
|
$ git checkout my2.6.14
|
||||||
|
|
||||||
|
<1> These two steps are the same as "checkout -b my2.6.14 v2.6.14".
|
||||||
|
------------
|
||||||
|
|
||||||
|
Delete unneeded branch::
|
||||||
|
+
|
||||||
|
------------
|
||||||
|
$ git clone git://git.kernel.org/.../git.git my.git
|
||||||
|
$ cd my.git
|
||||||
|
$ git branch -D todo <1>
|
||||||
|
|
||||||
|
<1> delete todo branch even if the "master" branch does not have all
|
||||||
|
commits from todo branch.
|
||||||
|
------------
|
||||||
|
|
||||||
Author
|
Author
|
||||||
------
|
------
|
||||||
Written by Linus Torvalds <torvalds@osdl.org> and Junio C Hamano <junkio@cox.net>
|
Written by Linus Torvalds <torvalds@osdl.org> and Junio C Hamano <junkio@cox.net>
|
||||||
|
|
|
@ -50,10 +50,14 @@ the `Makefile` to two revisions back, deletes hello.c by
|
||||||
mistake, and gets it back from the index.
|
mistake, and gets it back from the index.
|
||||||
|
|
||||||
------------
|
------------
|
||||||
$ git checkout master
|
$ git checkout master <1>
|
||||||
$ git checkout master~2 Makefile
|
$ git checkout master~2 Makefile <2>
|
||||||
$ rm -f hello.c
|
$ rm -f hello.c
|
||||||
$ git checkout hello.c
|
$ git checkout hello.c <3>
|
||||||
|
|
||||||
|
<1> switch branch
|
||||||
|
<2> take out a file out of other commit
|
||||||
|
<3> or "git checkout -- hello.c", as in the next example.
|
||||||
------------
|
------------
|
||||||
|
|
||||||
If you have an unfortunate branch that is named `hello.c`, the
|
If you have an unfortunate branch that is named `hello.c`, the
|
||||||
|
|
|
@ -74,10 +74,31 @@ OPTIONS
|
||||||
for "host.xz:foo/.git"). Cloning into an existing directory
|
for "host.xz:foo/.git"). Cloning into an existing directory
|
||||||
is not allowed.
|
is not allowed.
|
||||||
|
|
||||||
|
Examples
|
||||||
|
~~~~~~~~
|
||||||
|
|
||||||
|
Clone from upstream::
|
||||||
|
+
|
||||||
|
------------
|
||||||
|
$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
|
||||||
|
$ cd my2.6
|
||||||
|
$ make
|
||||||
|
------------
|
||||||
|
|
||||||
|
|
||||||
|
Make a local clone that borrows from the current directory, without checking things out::
|
||||||
|
+
|
||||||
|
------------
|
||||||
|
$ git clone -l -s -n . ../copy
|
||||||
|
$ cd copy
|
||||||
|
$ git show-branch
|
||||||
|
------------
|
||||||
|
|
||||||
Author
|
Author
|
||||||
------
|
------
|
||||||
Written by Linus Torvalds <torvalds@osdl.org>
|
Written by Linus Torvalds <torvalds@osdl.org>
|
||||||
|
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
--------------
|
--------------
|
||||||
Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
|
Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
|
||||||
|
|
|
@ -40,9 +40,12 @@ Start a new git repository for an existing code base::
|
||||||
+
|
+
|
||||||
----------------
|
----------------
|
||||||
$ cd /path/to/my/codebase
|
$ cd /path/to/my/codebase
|
||||||
$ git-init-db
|
$ git-init-db <1>
|
||||||
----------------
|
$ git-add . <2>
|
||||||
|
|
||||||
|
<1> prepare /path/to/my/codebase/.git directory
|
||||||
|
<2> add all existing file to the index
|
||||||
|
----------------
|
||||||
|
|
||||||
|
|
||||||
Author
|
Author
|
||||||
|
|
|
@ -42,6 +42,76 @@ OPTIONS
|
||||||
<commit-ish>::
|
<commit-ish>::
|
||||||
Commit to make the current HEAD.
|
Commit to make the current HEAD.
|
||||||
|
|
||||||
|
Examples
|
||||||
|
~~~~~~~~
|
||||||
|
|
||||||
|
Undo a commit and redo::
|
||||||
|
+
|
||||||
|
------------
|
||||||
|
$ git commit ...
|
||||||
|
$ git reset --soft HEAD^ <1>
|
||||||
|
$ edit <2>
|
||||||
|
$ git commit -a -c ORIG_HEAD <3>
|
||||||
|
|
||||||
|
<1> This is most often done when you remembered what you
|
||||||
|
just committed is incomplete, or you misspelled your commit
|
||||||
|
message, or both. Leaves working tree as it was before "reset".
|
||||||
|
<2> make corrections to working tree files.
|
||||||
|
<3> "reset" copies the old head to .git/ORIG_HEAD; redo the
|
||||||
|
commit by starting with its log message. If you do not need to
|
||||||
|
edit the message further, you can give -C option instead.
|
||||||
|
------------
|
||||||
|
|
||||||
|
Undo commits permanently::
|
||||||
|
+
|
||||||
|
------------
|
||||||
|
$ git commit ...
|
||||||
|
$ git reset --hard HEAD~3 <1>
|
||||||
|
|
||||||
|
<1> The last three commits (HEAD, HEAD^, and HEAD~2) were bad
|
||||||
|
and you do not want to ever see them again. Do *not* do this if
|
||||||
|
you have already given these commits to somebody else.
|
||||||
|
------------
|
||||||
|
|
||||||
|
Undo a commit, making it a topic branch::
|
||||||
|
+
|
||||||
|
------------
|
||||||
|
$ git branch topic/wip <1>
|
||||||
|
$ git reset --hard HEAD~3 <2>
|
||||||
|
$ git checkout topic/wip <3>
|
||||||
|
|
||||||
|
<1> You have made some commits, but realize they were premature
|
||||||
|
to be in the "master" branch. You want to continue polishing
|
||||||
|
them in a topic branch, so create "topic/wip" branch off of the
|
||||||
|
current HEAD.
|
||||||
|
<2> Rewind the master branch to get rid of those three commits.
|
||||||
|
<3> Switch to "topic/wip" branch and keep working.
|
||||||
|
------------
|
||||||
|
|
||||||
|
Undo update-index::
|
||||||
|
+
|
||||||
|
------------
|
||||||
|
$ edit <1>
|
||||||
|
$ git-update-index frotz.c filfre.c
|
||||||
|
$ mailx <2>
|
||||||
|
$ git reset <3>
|
||||||
|
$ git pull git://info.example.com/ nitfol <4>
|
||||||
|
|
||||||
|
<1> you are happily working on something, and find the changes
|
||||||
|
in these files are in good order. You do not want to see them
|
||||||
|
when you run "git diff", because you plan to work on other files
|
||||||
|
and changes with these files are distracting.
|
||||||
|
<2> somebody asks you to pull, and the changes sounds worthy of merging.
|
||||||
|
<3> however, you already dirtied the index (i.e. your index does
|
||||||
|
not match the HEAD commit). But you know the pull you are going
|
||||||
|
to make does not affect frotz.c nor filfre.c, so you revert the
|
||||||
|
index changes for these two files. Your changes in working tree
|
||||||
|
remain there.
|
||||||
|
<4> then you can pull and merge, leaving frotz.c and filfre.c
|
||||||
|
changes still in the working tree.
|
||||||
|
------------
|
||||||
|
|
||||||
|
|
||||||
Author
|
Author
|
||||||
------
|
------
|
||||||
Written by Junio C Hamano <junkio@cox.net> and Linus Torvalds <torvalds@osdl.org>
|
Written by Junio C Hamano <junkio@cox.net> and Linus Torvalds <torvalds@osdl.org>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче