THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

456 lines
14KB

  1. giteveryday(7)
  2. ==============
  3. NAME
  4. ----
  5. giteveryday - A useful minimum set of commands for Everyday Git
  6. SYNOPSIS
  7. --------
  8. Everyday Git With 20 Commands Or So
  9. DESCRIPTION
  10. -----------
  11. Git users can broadly be grouped into four categories for the purposes of
  12. describing here a small set of useful command for everyday Git.
  13. * <<STANDALONE,Individual Developer (Standalone)>> commands are essential
  14. for anybody who makes a commit, even for somebody who works alone.
  15. * If you work with other people, you will need commands listed in
  16. the <<PARTICIPANT,Individual Developer (Participant)>> section as well.
  17. * People who play the <<INTEGRATOR,Integrator>> role need to learn some
  18. more commands in addition to the above.
  19. * <<ADMINISTRATION,Repository Administration>> commands are for system
  20. administrators who are responsible for the care and feeding
  21. of Git repositories.
  22. Individual Developer (Standalone)[[STANDALONE]]
  23. -----------------------------------------------
  24. A standalone individual developer does not exchange patches with
  25. other people, and works alone in a single repository, using the
  26. following commands.
  27. * linkgit:git-init[1] to create a new repository.
  28. * linkgit:git-log[1] to see what happened.
  29. * linkgit:git-switch[1] and linkgit:git-branch[1] to switch
  30. branches.
  31. * linkgit:git-add[1] to manage the index file.
  32. * linkgit:git-diff[1] and linkgit:git-status[1] to see what
  33. you are in the middle of doing.
  34. * linkgit:git-commit[1] to advance the current branch.
  35. * linkgit:git-restore[1] to undo changes.
  36. * linkgit:git-merge[1] to merge between local branches.
  37. * linkgit:git-rebase[1] to maintain topic branches.
  38. * linkgit:git-tag[1] to mark a known point.
  39. Examples
  40. ~~~~~~~~
  41. Use a tarball as a starting point for a new repository.::
  42. +
  43. ------------
  44. $ tar zxf frotz.tar.gz
  45. $ cd frotz
  46. $ git init
  47. $ git add . <1>
  48. $ git commit -m "import of frotz source tree."
  49. $ git tag v2.43 <2>
  50. ------------
  51. +
  52. <1> add everything under the current directory.
  53. <2> make a lightweight, unannotated tag.
  54. Create a topic branch and develop.::
  55. +
  56. ------------
  57. $ git switch -c alsa-audio <1>
  58. $ edit/compile/test
  59. $ git restore curses/ux_audio_oss.c <2>
  60. $ git add curses/ux_audio_alsa.c <3>
  61. $ edit/compile/test
  62. $ git diff HEAD <4>
  63. $ git commit -a -s <5>
  64. $ edit/compile/test
  65. $ git diff HEAD^ <6>
  66. $ git commit -a --amend <7>
  67. $ git switch master <8>
  68. $ git merge alsa-audio <9>
  69. $ git log --since='3 days ago' <10>
  70. $ git log v2.43.. curses/ <11>
  71. ------------
  72. +
  73. <1> create a new topic branch.
  74. <2> revert your botched changes in `curses/ux_audio_oss.c`.
  75. <3> you need to tell Git if you added a new file; removal and
  76. modification will be caught if you do `git commit -a` later.
  77. <4> to see what changes you are committing.
  78. <5> commit everything, as you have tested, with your sign-off.
  79. <6> look at all your changes including the previous commit.
  80. <7> amend the previous commit, adding all your new changes,
  81. using your original message.
  82. <8> switch to the master branch.
  83. <9> merge a topic branch into your master branch.
  84. <10> review commit logs; other forms to limit output can be
  85. combined and include `-10` (to show up to 10 commits),
  86. `--until=2005-12-10`, etc.
  87. <11> view only the changes that touch what's in `curses/`
  88. directory, since `v2.43` tag.
  89. Individual Developer (Participant)[[PARTICIPANT]]
  90. -------------------------------------------------
  91. A developer working as a participant in a group project needs to
  92. learn how to communicate with others, and uses these commands in
  93. addition to the ones needed by a standalone developer.
  94. * linkgit:git-clone[1] from the upstream to prime your local
  95. repository.
  96. * linkgit:git-pull[1] and linkgit:git-fetch[1] from "origin"
  97. to keep up-to-date with the upstream.
  98. * linkgit:git-push[1] to shared repository, if you adopt CVS
  99. style shared repository workflow.
  100. * linkgit:git-format-patch[1] to prepare e-mail submission, if
  101. you adopt Linux kernel-style public forum workflow.
  102. * linkgit:git-send-email[1] to send your e-mail submission without
  103. corruption by your MUA.
  104. * linkgit:git-request-pull[1] to create a summary of changes
  105. for your upstream to pull.
  106. Examples
  107. ~~~~~~~~
  108. Clone the upstream and work on it. Feed changes to upstream.::
  109. +
  110. ------------
  111. $ git clone git://git.kernel.org/pub/scm/.../torvalds/linux-2.6 my2.6
  112. $ cd my2.6
  113. $ git switch -c mine master <1>
  114. $ edit/compile/test; git commit -a -s <2>
  115. $ git format-patch master <3>
  116. $ git send-email --to="person <email@example.com>" 00*.patch <4>
  117. $ git switch master <5>
  118. $ git pull <6>
  119. $ git log -p ORIG_HEAD.. arch/i386 include/asm-i386 <7>
  120. $ git ls-remote --heads http://git.kernel.org/.../jgarzik/libata-dev.git <8>
  121. $ git pull git://git.kernel.org/pub/.../jgarzik/libata-dev.git ALL <9>
  122. $ git reset --hard ORIG_HEAD <10>
  123. $ git gc <11>
  124. ------------
  125. +
  126. <1> checkout a new branch `mine` from master.
  127. <2> repeat as needed.
  128. <3> extract patches from your branch, relative to master,
  129. <4> and email them.
  130. <5> return to `master`, ready to see what's new
  131. <6> `git pull` fetches from `origin` by default and merges into the
  132. current branch.
  133. <7> immediately after pulling, look at the changes done upstream
  134. since last time we checked, only in the
  135. area we are interested in.
  136. <8> check the branch names in an external repository (if not known).
  137. <9> fetch from a specific branch `ALL` from a specific repository
  138. and merge it.
  139. <10> revert the pull.
  140. <11> garbage collect leftover objects from reverted pull.
  141. Push into another repository.::
  142. +
  143. ------------
  144. satellite$ git clone mothership:frotz frotz <1>
  145. satellite$ cd frotz
  146. satellite$ git config --get-regexp '^(remote|branch)\.' <2>
  147. remote.origin.url mothership:frotz
  148. remote.origin.fetch refs/heads/*:refs/remotes/origin/*
  149. branch.master.remote origin
  150. branch.master.merge refs/heads/master
  151. satellite$ git config remote.origin.push \
  152. +refs/heads/*:refs/remotes/satellite/* <3>
  153. satellite$ edit/compile/test/commit
  154. satellite$ git push origin <4>
  155. mothership$ cd frotz
  156. mothership$ git switch master
  157. mothership$ git merge satellite/master <5>
  158. ------------
  159. +
  160. <1> mothership machine has a frotz repository under your home
  161. directory; clone from it to start a repository on the satellite
  162. machine.
  163. <2> clone sets these configuration variables by default.
  164. It arranges `git pull` to fetch and store the branches of mothership
  165. machine to local `remotes/origin/*` remote-tracking branches.
  166. <3> arrange `git push` to push all local branches to
  167. their corresponding branch of the mothership machine.
  168. <4> push will stash all our work away on `remotes/satellite/*`
  169. remote-tracking branches on the mothership machine. You could use this
  170. as a back-up method. Likewise, you can pretend that mothership
  171. "fetched" from you (useful when access is one sided).
  172. <5> on mothership machine, merge the work done on the satellite
  173. machine into the master branch.
  174. Branch off of a specific tag.::
  175. +
  176. ------------
  177. $ git switch -c private2.6.14 v2.6.14 <1>
  178. $ edit/compile/test; git commit -a
  179. $ git checkout master
  180. $ git cherry-pick v2.6.14..private2.6.14 <2>
  181. ------------
  182. +
  183. <1> create a private branch based on a well known (but somewhat behind)
  184. tag.
  185. <2> forward port all changes in `private2.6.14` branch to `master` branch
  186. without a formal "merging". Or longhand +
  187. `git format-patch -k -m --stdout v2.6.14..private2.6.14 |
  188. git am -3 -k`
  189. An alternate participant submission mechanism is using the
  190. `git request-pull` or pull-request mechanisms (e.g as used on
  191. GitHub (www.github.com) to notify your upstream of your
  192. contribution.
  193. Integrator[[INTEGRATOR]]
  194. ------------------------
  195. A fairly central person acting as the integrator in a group
  196. project receives changes made by others, reviews and integrates
  197. them and publishes the result for others to use, using these
  198. commands in addition to the ones needed by participants.
  199. This section can also be used by those who respond to `git
  200. request-pull` or pull-request on GitHub (www.github.com) to
  201. integrate the work of others into their history. A sub-area
  202. lieutenant for a repository will act both as a participant and
  203. as an integrator.
  204. * linkgit:git-am[1] to apply patches e-mailed in from your
  205. contributors.
  206. * linkgit:git-pull[1] to merge from your trusted lieutenants.
  207. * linkgit:git-format-patch[1] to prepare and send suggested
  208. alternative to contributors.
  209. * linkgit:git-revert[1] to undo botched commits.
  210. * linkgit:git-push[1] to publish the bleeding edge.
  211. Examples
  212. ~~~~~~~~
  213. A typical integrator's Git day.::
  214. +
  215. ------------
  216. $ git status <1>
  217. $ git branch --no-merged master <2>
  218. $ mailx <3>
  219. & s 2 3 4 5 ./+to-apply
  220. & s 7 8 ./+hold-linus
  221. & q
  222. $ git switch -c topic/one master
  223. $ git am -3 -i -s ./+to-apply <4>
  224. $ compile/test
  225. $ git switch -c hold/linus && git am -3 -i -s ./+hold-linus <5>
  226. $ git switch topic/one && git rebase master <6>
  227. $ git switch -C pu next <7>
  228. $ git merge topic/one topic/two && git merge hold/linus <8>
  229. $ git switch maint
  230. $ git cherry-pick master~4 <9>
  231. $ compile/test
  232. $ git tag -s -m "GIT 0.99.9x" v0.99.9x <10>
  233. $ git fetch ko && for branch in master maint next pu <11>
  234. do
  235. git show-branch ko/$branch $branch <12>
  236. done
  237. $ git push --follow-tags ko <13>
  238. ------------
  239. +
  240. <1> see what you were in the middle of doing, if anything.
  241. <2> see which branches haven't been merged into `master` yet.
  242. Likewise for any other integration branches e.g. `maint`, `next`
  243. and `pu` (potential updates).
  244. <3> read mails, save ones that are applicable, and save others
  245. that are not quite ready (other mail readers are available).
  246. <4> apply them, interactively, with your sign-offs.
  247. <5> create topic branch as needed and apply, again with sign-offs.
  248. <6> rebase internal topic branch that has not been merged to the
  249. master or exposed as a part of a stable branch.
  250. <7> restart `pu` every time from the next.
  251. <8> and bundle topic branches still cooking.
  252. <9> backport a critical fix.
  253. <10> create a signed tag.
  254. <11> make sure master was not accidentally rewound beyond that
  255. already pushed out.
  256. <12> In the output from `git show-branch`, `master` should have
  257. everything `ko/master` has, and `next` should have
  258. everything `ko/next` has, etc.
  259. <13> push out the bleeding edge, together with new tags that point
  260. into the pushed history.
  261. In this example, the `ko` shorthand points at the Git maintainer's
  262. repository at kernel.org, and looks like this:
  263. ------------
  264. (in .git/config)
  265. [remote "ko"]
  266. url = kernel.org:/pub/scm/git/git.git
  267. fetch = refs/heads/*:refs/remotes/ko/*
  268. push = refs/heads/master
  269. push = refs/heads/next
  270. push = +refs/heads/pu
  271. push = refs/heads/maint
  272. ------------
  273. Repository Administration[[ADMINISTRATION]]
  274. -------------------------------------------
  275. A repository administrator uses the following tools to set up
  276. and maintain access to the repository by developers.
  277. * linkgit:git-daemon[1] to allow anonymous download from
  278. repository.
  279. * linkgit:git-shell[1] can be used as a 'restricted login shell'
  280. for shared central repository users.
  281. * linkgit:git-http-backend[1] provides a server side implementation
  282. of Git-over-HTTP ("Smart http") allowing both fetch and push services.
  283. * linkgit:gitweb[1] provides a web front-end to Git repositories,
  284. which can be set-up using the linkgit:git-instaweb[1] script.
  285. link:howto/update-hook-example.html[update hook howto] has a good
  286. example of managing a shared central repository.
  287. In addition there are a number of other widely deployed hosting, browsing
  288. and reviewing solutions such as:
  289. * gitolite, gerrit code review, cgit and others.
  290. Examples
  291. ~~~~~~~~
  292. We assume the following in /etc/services::
  293. +
  294. ------------
  295. $ grep 9418 /etc/services
  296. git 9418/tcp # Git Version Control System
  297. ------------
  298. Run git-daemon to serve /pub/scm from inetd.::
  299. +
  300. ------------
  301. $ grep git /etc/inetd.conf
  302. git stream tcp nowait nobody \
  303. /usr/bin/git-daemon git-daemon --inetd --export-all /pub/scm
  304. ------------
  305. +
  306. The actual configuration line should be on one line.
  307. Run git-daemon to serve /pub/scm from xinetd.::
  308. +
  309. ------------
  310. $ cat /etc/xinetd.d/git-daemon
  311. # default: off
  312. # description: The Git server offers access to Git repositories
  313. service git
  314. {
  315. disable = no
  316. type = UNLISTED
  317. port = 9418
  318. socket_type = stream
  319. wait = no
  320. user = nobody
  321. server = /usr/bin/git-daemon
  322. server_args = --inetd --export-all --base-path=/pub/scm
  323. log_on_failure += USERID
  324. }
  325. ------------
  326. +
  327. Check your xinetd(8) documentation and setup, this is from a Fedora system.
  328. Others might be different.
  329. Give push/pull only access to developers using git-over-ssh.::
  330. e.g. those using:
  331. `$ git push/pull ssh://host.xz/pub/scm/project`
  332. +
  333. ------------
  334. $ grep git /etc/passwd <1>
  335. alice:x:1000:1000::/home/alice:/usr/bin/git-shell
  336. bob:x:1001:1001::/home/bob:/usr/bin/git-shell
  337. cindy:x:1002:1002::/home/cindy:/usr/bin/git-shell
  338. david:x:1003:1003::/home/david:/usr/bin/git-shell
  339. $ grep git /etc/shells <2>
  340. /usr/bin/git-shell
  341. ------------
  342. +
  343. <1> log-in shell is set to /usr/bin/git-shell, which does not
  344. allow anything but `git push` and `git pull`. The users require
  345. ssh access to the machine.
  346. <2> in many distributions /etc/shells needs to list what is used
  347. as the login shell.
  348. CVS-style shared repository.::
  349. +
  350. ------------
  351. $ grep git /etc/group <1>
  352. git:x:9418:alice,bob,cindy,david
  353. $ cd /home/devo.git
  354. $ ls -l <2>
  355. lrwxrwxrwx 1 david git 17 Dec 4 22:40 HEAD -> refs/heads/master
  356. drwxrwsr-x 2 david git 4096 Dec 4 22:40 branches
  357. -rw-rw-r-- 1 david git 84 Dec 4 22:40 config
  358. -rw-rw-r-- 1 david git 58 Dec 4 22:40 description
  359. drwxrwsr-x 2 david git 4096 Dec 4 22:40 hooks
  360. -rw-rw-r-- 1 david git 37504 Dec 4 22:40 index
  361. drwxrwsr-x 2 david git 4096 Dec 4 22:40 info
  362. drwxrwsr-x 4 david git 4096 Dec 4 22:40 objects
  363. drwxrwsr-x 4 david git 4096 Nov 7 14:58 refs
  364. drwxrwsr-x 2 david git 4096 Dec 4 22:40 remotes
  365. $ ls -l hooks/update <3>
  366. -r-xr-xr-x 1 david git 3536 Dec 4 22:40 update
  367. $ cat info/allowed-users <4>
  368. refs/heads/master alice\|cindy
  369. refs/heads/doc-update bob
  370. refs/tags/v[0-9]* david
  371. ------------
  372. +
  373. <1> place the developers into the same git group.
  374. <2> and make the shared repository writable by the group.
  375. <3> use update-hook example by Carl from Documentation/howto/
  376. for branch policy control.
  377. <4> alice and cindy can push into master, only bob can push into doc-update.
  378. david is the release manager and is the only person who can
  379. create and push version tags.
  380. GIT
  381. ---
  382. Part of the linkgit:git[1] suite