commonmarker 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of commonmarker might be problematic. Click here for more details.

Files changed (501) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -2
  3. data/README.md +67 -42
  4. data/Rakefile +22 -2
  5. data/commonmarker.gemspec +13 -9
  6. data/ext/commonmarker/cmark/api_test/main.c +35 -0
  7. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeError.log +12 -12
  8. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log +141 -141
  9. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/main.c.o +0 -0
  10. data/ext/commonmarker/cmark/build/api_test/api_test +0 -0
  11. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/houdini_html_u.c.o +0 -0
  12. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/iterator.c.o +0 -0
  13. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/houdini_html_u.c.o +0 -0
  14. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/iterator.c.o +0 -0
  15. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/houdini_html_u.c.o +0 -0
  16. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/iterator.c.o +0 -0
  17. data/ext/commonmarker/cmark/build/src/cmark +0 -0
  18. data/ext/commonmarker/cmark/build/src/libcmark.0.19.0.dylib +0 -0
  19. data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
  20. data/ext/commonmarker/cmark/build/src/libcmark.dylib +0 -0
  21. data/ext/commonmarker/cmark/src/houdini_html_u.c +26 -13
  22. data/ext/commonmarker/cmark/src/iterator.c +2 -2
  23. data/ext/commonmarker/cmark/test/__pycache__/cmark.cpython-34.pyc +0 -0
  24. data/ext/commonmarker/cmark/test/__pycache__/normalize.cpython-34.pyc +0 -0
  25. data/ext/commonmarker/cmark/test/cmark.pyc +0 -0
  26. data/ext/commonmarker/cmark/test/normalize.pyc +0 -0
  27. data/ext/commonmarker/commonmarker.c +276 -3
  28. data/ext/commonmarker/extconf.rb +3 -1
  29. data/lib/commonmarker.rb +70 -360
  30. data/lib/commonmarker/config.rb +1 -1
  31. data/lib/commonmarker/renderer.rb +91 -0
  32. data/lib/commonmarker/renderer/html_renderer.rb +149 -0
  33. data/lib/commonmarker/version.rb +1 -1
  34. data/test/benchinput.md +148414 -0
  35. data/test/benchmark.rb +13 -9
  36. data/test/progit/Gemfile +5 -0
  37. data/test/progit/README.md +9 -0
  38. data/test/progit/README.original.md +70 -0
  39. data/test/progit/Rakefile +285 -0
  40. data/test/progit/ar/01-introduction/01-chapter1.markdown +264 -0
  41. data/test/progit/ar/02-git-basics/01-chapter2.markdown +1124 -0
  42. data/test/progit/ar/NOTES +18 -0
  43. data/test/progit/ar/README +14 -0
  44. data/test/progit/az/01-introduction/01-chapter1.markdown +257 -0
  45. data/test/progit/az/02-git-basics/01-chapter2.markdown +1127 -0
  46. data/test/progit/az/03-git-branching/01-chapter3.markdown +598 -0
  47. data/test/progit/az/04-git-server/01-chapter4.markdown +861 -0
  48. data/test/progit/az/05-distributed-git/01-chapter5.markdown +897 -0
  49. data/test/progit/az/06-git-tools/01-chapter6.markdown +1126 -0
  50. data/test/progit/az/07-customizing-git/01-chapter7.markdown +937 -0
  51. data/test/progit/az/08-git-and-other-scms/01-chapter8.markdown +690 -0
  52. data/test/progit/az/09-git-internals/01-chapter9.markdown +977 -0
  53. data/test/progit/be/01-introduction/01-chapter1.markdown +257 -0
  54. data/test/progit/be/02-git-basics/01-chapter2.markdown +1126 -0
  55. data/test/progit/ca/01-introduction/01-chapter1.markdown +257 -0
  56. data/test/progit/ca/README.txt +1 -0
  57. data/test/progit/couchapp/Makefile +41 -0
  58. data/test/progit/couchapp/Readme.md +17 -0
  59. data/test/progit/couchapp/_id +1 -0
  60. data/test/progit/couchapp/shows/chapter.js +14 -0
  61. data/test/progit/couchapp/templates/foot.html +7 -0
  62. data/test/progit/couchapp/templates/head.html +51 -0
  63. data/test/progit/couchapp/vendor/markdown/showdown.js +420 -0
  64. data/test/progit/couchapp/vendor/mustache.js/mustache.js +302 -0
  65. data/test/progit/cs/01-introduction/01-chapter1.markdown +259 -0
  66. data/test/progit/cs/02-git-basics/01-chapter2.markdown +1225 -0
  67. data/test/progit/cs/03-git-branching/01-chapter3.markdown +606 -0
  68. data/test/progit/cs/04-git-server/01-chapter4.markdown +871 -0
  69. data/test/progit/cs/05-distributed-git/01-chapter5.markdown +914 -0
  70. data/test/progit/cs/06-git-tools/01-chapter6.markdown +1167 -0
  71. data/test/progit/cs/07-customizing-git/01-chapter7.markdown +940 -0
  72. data/test/progit/cs/08-git-and-other-scms/01-chapter8.markdown +700 -0
  73. data/test/progit/cs/09-git-internals/01-chapter9.markdown +1014 -0
  74. data/test/progit/de/01-introduction/01-chapter1.markdown +445 -0
  75. data/test/progit/de/02-git-basics/01-chapter2.markdown +1589 -0
  76. data/test/progit/de/03-git-branching/01-chapter3.markdown +964 -0
  77. data/test/progit/de/04-git-server/01-chapter4.markdown +1337 -0
  78. data/test/progit/de/05-distributed-git/01-chapter5.markdown +1329 -0
  79. data/test/progit/de/06-git-tools/01-chapter6.markdown +1502 -0
  80. data/test/progit/de/07-customizing-git/01-chapter7.markdown +1361 -0
  81. data/test/progit/de/08-git-and-other-scms/01-chapter8.markdown +919 -0
  82. data/test/progit/de/09-git-internals/01-chapter9.markdown +1361 -0
  83. data/test/progit/de/README.md +626 -0
  84. data/test/progit/ebooks/cover.png +0 -0
  85. data/test/progit/en/01-introduction/01-chapter1.markdown +263 -0
  86. data/test/progit/en/02-git-basics/01-chapter2.markdown +1228 -0
  87. data/test/progit/en/03-git-branching/01-chapter3.markdown +606 -0
  88. data/test/progit/en/04-git-server/01-chapter4.markdown +871 -0
  89. data/test/progit/en/05-distributed-git/01-chapter5.markdown +914 -0
  90. data/test/progit/en/06-git-tools/01-chapter6.markdown +1150 -0
  91. data/test/progit/en/07-customizing-git/01-chapter7.markdown +940 -0
  92. data/test/progit/en/08-git-and-other-scms/01-chapter8.markdown +700 -0
  93. data/test/progit/en/09-git-internals/01-chapter9.markdown +983 -0
  94. data/test/progit/eo/01-introduction/01-chapter1.markdown +257 -0
  95. data/test/progit/eo/02-git-basics/01-chapter2.markdown +1171 -0
  96. data/test/progit/epub/ProGit.css +28 -0
  97. data/test/progit/epub/title.png +0 -0
  98. data/test/progit/es-ni/01-introduction/01-chapter1.markdown +257 -0
  99. data/test/progit/es-ni/02-git-basics/01-chapter2.markdown +1127 -0
  100. data/test/progit/es/01-introduction/01-chapter1.markdown +262 -0
  101. data/test/progit/es/02-git-basics/01-chapter2.markdown +1165 -0
  102. data/test/progit/es/03-git-branching/01-chapter3.markdown +598 -0
  103. data/test/progit/es/04-git-server/01-chapter4.markdown +707 -0
  104. data/test/progit/es/05-distributed-git/01-chapter5.markdown +890 -0
  105. data/test/progit/es/06-git-tools/01-chapter6.markdown +1113 -0
  106. data/test/progit/es/07-customizing-git/01-chapter7.markdown +875 -0
  107. data/test/progit/es/08-git-and-other-scms/01-chapter8.markdown +686 -0
  108. data/test/progit/es/09-git-internals/01-chapter9.markdown +976 -0
  109. data/test/progit/es/NOTES +29 -0
  110. data/test/progit/es/README +3 -0
  111. data/test/progit/es/glosario-Benzirpi.txt +27 -0
  112. data/test/progit/es/omegat-Benzirpi.tmx +29075 -0
  113. data/test/progit/fa/01-introduction/01-chapter1.markdown +262 -0
  114. data/test/progit/fa/03-git-branching/01-chapter3.markdown +608 -0
  115. data/test/progit/fa/04-git-server/01-chapter4.markdown +872 -0
  116. data/test/progit/fa/NOTES.en-fa.md +143 -0
  117. data/test/progit/fa/README.md +7 -0
  118. data/test/progit/fi/01-introduction/01-chapter1.markdown +259 -0
  119. data/test/progit/fi/02-git-basics/01-chapter2.markdown +1171 -0
  120. data/test/progit/fi/NOTES +5 -0
  121. data/test/progit/figures-dia/fig0101.dia +617 -0
  122. data/test/progit/figures-dia/fig0102.dia +921 -0
  123. data/test/progit/figures-dia/fig0103.dia +1468 -0
  124. data/test/progit/figures-dia/fig0104.dia +1432 -0
  125. data/test/progit/figures-dia/fig0105.dia +1924 -0
  126. data/test/progit/figures-dia/fig0106.dia +562 -0
  127. data/test/progit/figures-dia/fig0201.dia +774 -0
  128. data/test/progit/figures-dia/fig0301.dia +2006 -0
  129. data/test/progit/figures-dia/fig0302.dia +2148 -0
  130. data/test/progit/figures-dia/fig0303.dia +719 -0
  131. data/test/progit/figures-dia/fig0304.dia +525 -0
  132. data/test/progit/figures-dia/fig0305.dia +622 -0
  133. data/test/progit/figures-dia/fig0306.dia +622 -0
  134. data/test/progit/figures-dia/fig0307.dia +719 -0
  135. data/test/progit/figures-dia/fig0308.dia +734 -0
  136. data/test/progit/figures-dia/fig0309.dia +831 -0
  137. data/test/progit/figures-dia/fig0310.dia +412 -0
  138. data/test/progit/figures-dia/fig0311.dia +493 -0
  139. data/test/progit/figures-dia/fig0312.dia +596 -0
  140. data/test/progit/figures-dia/fig0313.dia +774 -0
  141. data/test/progit/figures-dia/fig0314.dia +846 -0
  142. data/test/progit/figures-dia/fig0315.dia +787 -0
  143. data/test/progit/figures-dia/fig0316.dia +1078 -0
  144. data/test/progit/figures-dia/fig0317.dia +881 -0
  145. data/test/progit/figures-dia/fig0318.dia +968 -0
  146. data/test/progit/figures-dia/fig0319.dia +957 -0
  147. data/test/progit/figures-dia/fig0320.dia +1637 -0
  148. data/test/progit/figures-dia/fig0321.dia +1494 -0
  149. data/test/progit/figures-dia/fig0322.dia +1142 -0
  150. data/test/progit/figures-dia/fig0323.dia +1377 -0
  151. data/test/progit/figures-dia/fig0324.dia +1603 -0
  152. data/test/progit/figures-dia/fig0325.dia +2003 -0
  153. data/test/progit/figures-dia/fig0326.dia +2013 -0
  154. data/test/progit/figures-dia/fig0327.dia +687 -0
  155. data/test/progit/figures-dia/fig0328.dia +814 -0
  156. data/test/progit/figures-dia/fig0329.dia +793 -0
  157. data/test/progit/figures-dia/fig0330.dia +693 -0
  158. data/test/progit/figures-dia/fig0331.dia +1159 -0
  159. data/test/progit/figures-dia/fig0332.dia +1362 -0
  160. data/test/progit/figures-dia/fig0333.dia +1165 -0
  161. data/test/progit/figures-dia/fig0334.dia +1450 -0
  162. data/test/progit/figures-dia/fig0335.dia +994 -0
  163. data/test/progit/figures-dia/fig0336.dia +786 -0
  164. data/test/progit/figures-dia/fig0337.dia +1546 -0
  165. data/test/progit/figures-dia/fig0338.dia +1755 -0
  166. data/test/progit/figures-dia/fig0339.dia +1882 -0
  167. data/test/progit/figures-dia/fig0501.dia +456 -0
  168. data/test/progit/figures-dia/fig0502.dia +956 -0
  169. data/test/progit/figures-dia/fig0503.dia +915 -0
  170. data/test/progit/figures-dia/fig0504.dia +620 -0
  171. data/test/progit/figures-dia/fig0505.dia +744 -0
  172. data/test/progit/figures-dia/fig0506.dia +747 -0
  173. data/test/progit/figures-dia/fig0507.dia +895 -0
  174. data/test/progit/figures-dia/fig0508.dia +1122 -0
  175. data/test/progit/figures-dia/fig0509.dia +1243 -0
  176. data/test/progit/figures-dia/fig0510.dia +1240 -0
  177. data/test/progit/figures-dia/fig0511.dia +1201 -0
  178. data/test/progit/figures-dia/fig0512.dia +801 -0
  179. data/test/progit/figures-dia/fig0513.dia +1387 -0
  180. data/test/progit/figures-dia/fig0514.dia +1568 -0
  181. data/test/progit/figures-dia/fig0515.dia +1721 -0
  182. data/test/progit/figures-dia/fig0516.dia +997 -0
  183. data/test/progit/figures-dia/fig0517.dia +994 -0
  184. data/test/progit/figures-dia/fig0518.dia +1145 -0
  185. data/test/progit/figures-dia/fig0519.dia +992 -0
  186. data/test/progit/figures-dia/fig0520.dia +1240 -0
  187. data/test/progit/figures-dia/fig0521.dia +801 -0
  188. data/test/progit/figures-dia/fig0522.dia +922 -0
  189. data/test/progit/figures-dia/fig0523.dia +922 -0
  190. data/test/progit/figures-dia/fig0524.dia +1828 -0
  191. data/test/progit/figures-dia/fig0525.dia +2685 -0
  192. data/test/progit/figures-dia/fig0526.dia +717 -0
  193. data/test/progit/figures-dia/fig0527.dia +856 -0
  194. data/test/progit/figures-dia/fig0601.dia +790 -0
  195. data/test/progit/figures-dia/fig0702.dia +795 -0
  196. data/test/progit/figures-dia/fig0703.dia +795 -0
  197. data/test/progit/figures-dia/fig0901.dia +669 -0
  198. data/test/progit/figures-dia/fig0902.dia +834 -0
  199. data/test/progit/figures-dia/fig0903.dia +1483 -0
  200. data/test/progit/figures-dia/fig0904.dia +1728 -0
  201. data/test/progit/figures-dia/makeimages +25 -0
  202. data/test/progit/figures-source/progit.graffle +123108 -0
  203. data/test/progit/figures/18333fig0101-tn.png +0 -0
  204. data/test/progit/figures/18333fig0102-tn.png +0 -0
  205. data/test/progit/figures/18333fig0103-tn.png +0 -0
  206. data/test/progit/figures/18333fig0104-tn.png +0 -0
  207. data/test/progit/figures/18333fig0105-tn.png +0 -0
  208. data/test/progit/figures/18333fig0106-tn.png +0 -0
  209. data/test/progit/figures/18333fig0107-tn.png +0 -0
  210. data/test/progit/figures/18333fig0201-tn.png +0 -0
  211. data/test/progit/figures/18333fig0202-tn.png +0 -0
  212. data/test/progit/figures/18333fig0301-tn.png +0 -0
  213. data/test/progit/figures/18333fig0302-tn.png +0 -0
  214. data/test/progit/figures/18333fig0303-tn.png +0 -0
  215. data/test/progit/figures/18333fig0304-tn.png +0 -0
  216. data/test/progit/figures/18333fig0305-tn.png +0 -0
  217. data/test/progit/figures/18333fig0306-tn.png +0 -0
  218. data/test/progit/figures/18333fig0307-tn.png +0 -0
  219. data/test/progit/figures/18333fig0308-tn.png +0 -0
  220. data/test/progit/figures/18333fig0309-tn.png +0 -0
  221. data/test/progit/figures/18333fig0310-tn.png +0 -0
  222. data/test/progit/figures/18333fig0311-tn.png +0 -0
  223. data/test/progit/figures/18333fig0312-tn.png +0 -0
  224. data/test/progit/figures/18333fig0313-tn.png +0 -0
  225. data/test/progit/figures/18333fig0314-tn.png +0 -0
  226. data/test/progit/figures/18333fig0315-tn.png +0 -0
  227. data/test/progit/figures/18333fig0316-tn.png +0 -0
  228. data/test/progit/figures/18333fig0317-tn.png +0 -0
  229. data/test/progit/figures/18333fig0318-tn.png +0 -0
  230. data/test/progit/figures/18333fig0319-tn.png +0 -0
  231. data/test/progit/figures/18333fig0320-tn.png +0 -0
  232. data/test/progit/figures/18333fig0321-tn.png +0 -0
  233. data/test/progit/figures/18333fig0322-tn.png +0 -0
  234. data/test/progit/figures/18333fig0323-tn.png +0 -0
  235. data/test/progit/figures/18333fig0324-tn.png +0 -0
  236. data/test/progit/figures/18333fig0325-tn.png +0 -0
  237. data/test/progit/figures/18333fig0326-tn.png +0 -0
  238. data/test/progit/figures/18333fig0327-tn.png +0 -0
  239. data/test/progit/figures/18333fig0328-tn.png +0 -0
  240. data/test/progit/figures/18333fig0329-tn.png +0 -0
  241. data/test/progit/figures/18333fig0330-tn.png +0 -0
  242. data/test/progit/figures/18333fig0331-tn.png +0 -0
  243. data/test/progit/figures/18333fig0332-tn.png +0 -0
  244. data/test/progit/figures/18333fig0333-tn.png +0 -0
  245. data/test/progit/figures/18333fig0334-tn.png +0 -0
  246. data/test/progit/figures/18333fig0335-tn.png +0 -0
  247. data/test/progit/figures/18333fig0336-tn.png +0 -0
  248. data/test/progit/figures/18333fig0337-tn.png +0 -0
  249. data/test/progit/figures/18333fig0338-tn.png +0 -0
  250. data/test/progit/figures/18333fig0339-tn.png +0 -0
  251. data/test/progit/figures/18333fig0401-tn.png +0 -0
  252. data/test/progit/figures/18333fig0402-tn.png +0 -0
  253. data/test/progit/figures/18333fig0403-tn.png +0 -0
  254. data/test/progit/figures/18333fig0404-tn.png +0 -0
  255. data/test/progit/figures/18333fig0405-tn.png +0 -0
  256. data/test/progit/figures/18333fig0406-tn.png +0 -0
  257. data/test/progit/figures/18333fig0407-tn.png +0 -0
  258. data/test/progit/figures/18333fig0408-tn.png +0 -0
  259. data/test/progit/figures/18333fig0409-tn.png +0 -0
  260. data/test/progit/figures/18333fig0410-tn.png +0 -0
  261. data/test/progit/figures/18333fig0411-tn.png +0 -0
  262. data/test/progit/figures/18333fig0412-tn.png +0 -0
  263. data/test/progit/figures/18333fig0413-tn.png +0 -0
  264. data/test/progit/figures/18333fig0414-tn.png +0 -0
  265. data/test/progit/figures/18333fig0415-tn.png +0 -0
  266. data/test/progit/figures/18333fig0501-tn.png +0 -0
  267. data/test/progit/figures/18333fig0502-tn.png +0 -0
  268. data/test/progit/figures/18333fig0503-tn.png +0 -0
  269. data/test/progit/figures/18333fig0504-tn.png +0 -0
  270. data/test/progit/figures/18333fig0505-tn.png +0 -0
  271. data/test/progit/figures/18333fig0506-tn.png +0 -0
  272. data/test/progit/figures/18333fig0507-tn.png +0 -0
  273. data/test/progit/figures/18333fig0508-tn.png +0 -0
  274. data/test/progit/figures/18333fig0509-tn.png +0 -0
  275. data/test/progit/figures/18333fig0510-tn.png +0 -0
  276. data/test/progit/figures/18333fig0511-tn.png +0 -0
  277. data/test/progit/figures/18333fig0512-tn.png +0 -0
  278. data/test/progit/figures/18333fig0513-tn.png +0 -0
  279. data/test/progit/figures/18333fig0514-tn.png +0 -0
  280. data/test/progit/figures/18333fig0515-tn.png +0 -0
  281. data/test/progit/figures/18333fig0516-tn.png +0 -0
  282. data/test/progit/figures/18333fig0517-tn.png +0 -0
  283. data/test/progit/figures/18333fig0518-tn.png +0 -0
  284. data/test/progit/figures/18333fig0519-tn.png +0 -0
  285. data/test/progit/figures/18333fig0520-tn.png +0 -0
  286. data/test/progit/figures/18333fig0521-tn.png +0 -0
  287. data/test/progit/figures/18333fig0522-tn.png +0 -0
  288. data/test/progit/figures/18333fig0523-tn.png +0 -0
  289. data/test/progit/figures/18333fig0524-tn.png +0 -0
  290. data/test/progit/figures/18333fig0525-tn.png +0 -0
  291. data/test/progit/figures/18333fig0526-tn.png +0 -0
  292. data/test/progit/figures/18333fig0527-tn.png +0 -0
  293. data/test/progit/figures/18333fig0601-tn.png +0 -0
  294. data/test/progit/figures/18333fig0701-tn.png +0 -0
  295. data/test/progit/figures/18333fig0702-tn.png +0 -0
  296. data/test/progit/figures/18333fig0703-tn.png +0 -0
  297. data/test/progit/figures/18333fig0901-tn.png +0 -0
  298. data/test/progit/figures/18333fig0902-tn.png +0 -0
  299. data/test/progit/figures/18333fig0903-tn.png +0 -0
  300. data/test/progit/figures/18333fig0904-tn.png +0 -0
  301. data/test/progit/fr/01-introduction/01-chapter1.markdown +371 -0
  302. data/test/progit/fr/02-git-basics/01-chapter2.markdown +1378 -0
  303. data/test/progit/fr/03-git-branching/01-chapter3.markdown +781 -0
  304. data/test/progit/fr/04-git-server/01-chapter4.markdown +1141 -0
  305. data/test/progit/fr/05-distributed-git/01-chapter5.markdown +1163 -0
  306. data/test/progit/fr/06-git-tools/01-chapter6.markdown +1356 -0
  307. data/test/progit/fr/07-customizing-git/01-chapter7.markdown +1200 -0
  308. data/test/progit/fr/08-git-and-other-scms/01-chapter8.markdown +832 -0
  309. data/test/progit/fr/09-git-internals/01-chapter9.markdown +1228 -0
  310. data/test/progit/fr/NOTES.fr-fr.markdown +1 -0
  311. data/test/progit/fr/NOTES.fr-fr.md +127 -0
  312. data/test/progit/fr/README.md +43 -0
  313. data/test/progit/fr/glossaire-git.adoc +108 -0
  314. data/test/progit/hi/01-introduction/01-chapter1.markdown +7 -0
  315. data/test/progit/hu/01-introduction/01-chapter1.markdown +257 -0
  316. data/test/progit/id/01-introduction/01-chapter1.markdown +257 -0
  317. data/test/progit/id/02-git-basics/01-chapter2.markdown +1127 -0
  318. data/test/progit/id/03-git-branching/01-chapter3.markdown +598 -0
  319. data/test/progit/it/01-introduction/01-chapter1.markdown +263 -0
  320. data/test/progit/it/02-git-basics/01-chapter2.markdown +1227 -0
  321. data/test/progit/it/03-git-branching/01-chapter3.markdown +598 -0
  322. data/test/progit/it/04-git-server/01-chapter4.markdown +864 -0
  323. data/test/progit/it/05-distributed-git/01-chapter5.markdown +897 -0
  324. data/test/progit/it/06-git-tools/01-chapter6.markdown +1144 -0
  325. data/test/progit/it/07-customizing-git/01-chapter7.markdown +606 -0
  326. data/test/progit/it/08-git-and-other-scms/01-chapter8.markdown +707 -0
  327. data/test/progit/it/09-git-internals/01-chapter9.markdown +1000 -0
  328. data/test/progit/ja/01-introduction/01-chapter1.markdown +260 -0
  329. data/test/progit/ja/02-git-basics/01-chapter2.markdown +1221 -0
  330. data/test/progit/ja/03-git-branching/01-chapter3.markdown +604 -0
  331. data/test/progit/ja/04-git-server/01-chapter4.markdown +863 -0
  332. data/test/progit/ja/05-distributed-git/01-chapter5.markdown +908 -0
  333. data/test/progit/ja/06-git-tools/01-chapter6.markdown +1133 -0
  334. data/test/progit/ja/07-customizing-git/01-chapter7.markdown +936 -0
  335. data/test/progit/ja/08-git-and-other-scms/01-chapter8.markdown +690 -0
  336. data/test/progit/ja/09-git-internals/01-chapter9.markdown +984 -0
  337. data/test/progit/ja/README.md +58 -0
  338. data/test/progit/ja/translation glossaries.txt +33 -0
  339. data/test/progit/ko/01-introduction/01-chapter1.markdown +258 -0
  340. data/test/progit/ko/02-git-basics/01-chapter2.markdown +1181 -0
  341. data/test/progit/ko/03-git-branching/01-chapter3.markdown +612 -0
  342. data/test/progit/ko/04-git-server/01-chapter4.markdown +867 -0
  343. data/test/progit/ko/05-distributed-git/01-chapter5.markdown +913 -0
  344. data/test/progit/ko/06-git-tools/01-chapter6.markdown +1142 -0
  345. data/test/progit/ko/07-customizing-git/01-chapter7.markdown +935 -0
  346. data/test/progit/ko/08-git-and-other-scms/01-chapter8.markdown +688 -0
  347. data/test/progit/ko/09-git-internals/01-chapter9.markdown +976 -0
  348. data/test/progit/ko/README.md +75 -0
  349. data/test/progit/ko/translation_guide.txt +65 -0
  350. data/test/progit/latex/README +27 -0
  351. data/test/progit/latex/config.yml +144 -0
  352. data/test/progit/latex/makepdf +207 -0
  353. data/test/progit/latex/template.tex +155 -0
  354. data/test/progit/makeebooks +125 -0
  355. data/test/progit/makepdfs +47 -0
  356. data/test/progit/mk/01-introduction/01-chapter1.markdown +258 -0
  357. data/test/progit/mk/02-git-basics/01-chapter2.markdown +1125 -0
  358. data/test/progit/mk/03-git-branching/01-chapter3.markdown +598 -0
  359. data/test/progit/mk/05-distributed-git/01-chapter5.markdown +897 -0
  360. data/test/progit/nl/01-introduction/01-chapter1.markdown +296 -0
  361. data/test/progit/nl/02-git-basics/01-chapter2.markdown +1253 -0
  362. data/test/progit/nl/03-git-branching/01-chapter3.markdown +642 -0
  363. data/test/progit/nl/04-git-server/01-chapter4.markdown +902 -0
  364. data/test/progit/nl/05-distributed-git/01-chapter5.markdown +953 -0
  365. data/test/progit/nl/06-git-tools/01-chapter6.markdown +1177 -0
  366. data/test/progit/nl/07-customizing-git/01-chapter7.markdown +974 -0
  367. data/test/progit/nl/08-git-and-other-scms/01-chapter8.markdown +725 -0
  368. data/test/progit/nl/09-git-internals/01-chapter9.markdown +1013 -0
  369. data/test/progit/no-nb/01-introduction/01-chapter1.markdown +261 -0
  370. data/test/progit/no-nb/02-git-basics/01-chapter2.markdown +1225 -0
  371. data/test/progit/no-nb/03-git-branching/01-chapter3.markdown +606 -0
  372. data/test/progit/no-nb/04-git-server/01-chapter4.markdown +867 -0
  373. data/test/progit/no-nb/05-distributed-git/01-chapter5.markdown +914 -0
  374. data/test/progit/no-nb/06-git-tools/01-chapter6.markdown +1144 -0
  375. data/test/progit/no-nb/07-customizing-git/01-chapter7.markdown +936 -0
  376. data/test/progit/no-nb/08-git-and-other-scms/01-chapter8.markdown +689 -0
  377. data/test/progit/no-nb/09-git-internals/01-chapter9.markdown +977 -0
  378. data/test/progit/no-nb/README +2 -0
  379. data/test/progit/pl/01-introduction/01-chapter1.markdown +257 -0
  380. data/test/progit/pl/02-git-basics/02-chapter2.markdown +1128 -0
  381. data/test/progit/pl/03-git-branching/01-chapter3.markdown +598 -0
  382. data/test/progit/pl/04-git-server/01-chapter4.markdown +897 -0
  383. data/test/progit/pl/05-distributed-git/01-chapter5.markdown +1278 -0
  384. data/test/progit/pl/06-git-tools/01-chapter6.markdown +1550 -0
  385. data/test/progit/pl/07-customizing-git/01-chapter7.markdown +1058 -0
  386. data/test/progit/pl/08-git-and-other-scms/01-chapter8.markdown +948 -0
  387. data/test/progit/pl/09-git-internals/01-chapter9.markdown +1382 -0
  388. data/test/progit/pl/translation-guidelines.txt +70 -0
  389. data/test/progit/pt-br/01-introduction/01-chapter1.markdown +256 -0
  390. data/test/progit/pt-br/02-git-basics/01-chapter2.markdown +1127 -0
  391. data/test/progit/pt-br/03-git-branching/01-chapter3.markdown +596 -0
  392. data/test/progit/pt-br/04-git-server/01-chapter4.markdown +888 -0
  393. data/test/progit/pt-br/05-distributed-git/01-chapter5.markdown +896 -0
  394. data/test/progit/pt-br/06-git-tools/01-chapter6.markdown +1122 -0
  395. data/test/progit/pt-br/07-customizing-git/01-chapter7.markdown +932 -0
  396. data/test/progit/pt-br/08-git-and-other-scms/01-chapter8.markdown +691 -0
  397. data/test/progit/pt-br/09-git-internals/01-chapter9.markdown +978 -0
  398. data/test/progit/pt-br/figures-dia/fig0101.dia +617 -0
  399. data/test/progit/pt-br/figures-dia/fig0102.dia +921 -0
  400. data/test/progit/pt-br/figures-dia/fig0103.dia +1468 -0
  401. data/test/progit/pt-br/figures-dia/fig0104.dia +1432 -0
  402. data/test/progit/pt-br/figures-dia/fig0105.dia +1924 -0
  403. data/test/progit/pt-br/figures-dia/fig0106.dia +562 -0
  404. data/test/progit/pt-br/figures-dia/fig0201.dia +776 -0
  405. data/test/progit/pt-br/figures-dia/fig0301.dia +2006 -0
  406. data/test/progit/pt-br/figures-dia/fig0302.dia +2148 -0
  407. data/test/progit/pt-br/figures-dia/fig0316.dia +1079 -0
  408. data/test/progit/pt-br/figures-dia/fig0322.dia +1142 -0
  409. data/test/progit/pt-br/figures-dia/fig0323.dia +1407 -0
  410. data/test/progit/pt-br/figures-dia/fig0324.dia +1603 -0
  411. data/test/progit/pt-br/figures-dia/fig0325.dia +2003 -0
  412. data/test/progit/pt-br/figures-dia/fig0326.dia +2013 -0
  413. data/test/progit/pt-br/figures-dia/fig0336.dia +786 -0
  414. data/test/progit/pt-br/figures-dia/fig0337.dia +1546 -0
  415. data/test/progit/pt-br/figures-dia/fig0338.dia +1755 -0
  416. data/test/progit/pt-br/figures-dia/fig0339.dia +1882 -0
  417. data/test/progit/pt-br/figures-dia/fig0501.dia +456 -0
  418. data/test/progit/pt-br/figures-dia/fig0502.dia +965 -0
  419. data/test/progit/pt-br/figures-dia/fig0503.dia +914 -0
  420. data/test/progit/pt-br/figures-dia/fig0511.dia +1201 -0
  421. data/test/progit/pt-br/figures-dia/fig0515.dia +1721 -0
  422. data/test/progit/pt-br/figures-dia/fig0702.dia +795 -0
  423. data/test/progit/pt-br/figures-dia/fig0703.dia +795 -0
  424. data/test/progit/pt-br/figures-dia/fig0901.dia +669 -0
  425. data/test/progit/pt-br/figures-dia/fig0902.dia +834 -0
  426. data/test/progit/pt-br/figures-dia/fig0903.dia +1483 -0
  427. data/test/progit/pt-br/figures-dia/fig0904.dia +1728 -0
  428. data/test/progit/ro/01-introduction/01-chapter1.markdown +257 -0
  429. data/test/progit/ru/01-introduction/01-chapter1.markdown +259 -0
  430. data/test/progit/ru/02-git-basics/01-chapter2.markdown +1155 -0
  431. data/test/progit/ru/03-git-branching/01-chapter3.markdown +598 -0
  432. data/test/progit/ru/04-git-server/01-chapter4.markdown +854 -0
  433. data/test/progit/ru/05-distributed-git/01-chapter5.markdown +897 -0
  434. data/test/progit/ru/06-git-tools/01-chapter6.markdown +1126 -0
  435. data/test/progit/ru/07-customizing-git/01-chapter7.markdown +938 -0
  436. data/test/progit/ru/08-git-and-other-scms/01-chapter8.markdown +691 -0
  437. data/test/progit/ru/09-git-internals/01-chapter9.markdown +977 -0
  438. data/test/progit/ru/Glossary +38 -0
  439. data/test/progit/ru/README +12 -0
  440. data/test/progit/ru/figures-dia/fig0101.dia +647 -0
  441. data/test/progit/ru/figures-dia/fig0102.dia +1009 -0
  442. data/test/progit/ru/figures-dia/fig0103.dia +1468 -0
  443. data/test/progit/ru/figures-dia/fig0104.dia +1432 -0
  444. data/test/progit/ru/figures-dia/fig0105.dia +1924 -0
  445. data/test/progit/ru/figures-dia/fig0106.dia +561 -0
  446. data/test/progit/ru/figures-dia/fig0201.dia +774 -0
  447. data/test/progit/ru/figures-dia/fig0322.dia +1182 -0
  448. data/test/progit/ru/figures-dia/fig0323.dia +1457 -0
  449. data/test/progit/ru/figures-dia/fig0324.dia +1698 -0
  450. data/test/progit/ru/figures-dia/fig0325.dia +2101 -0
  451. data/test/progit/ru/figures-dia/fig0326.dia +2111 -0
  452. data/test/progit/ru/figures-dia/fig0336.dia +786 -0
  453. data/test/progit/ru/figures-dia/fig0337.dia +1546 -0
  454. data/test/progit/ru/figures-dia/fig0338.dia +1755 -0
  455. data/test/progit/ru/figures-dia/fig0339.dia +1882 -0
  456. data/test/progit/ru/figures-dia/fig0501.dia +477 -0
  457. data/test/progit/ru/figures-dia/fig0502.dia +1063 -0
  458. data/test/progit/ru/figures-dia/fig0503.dia +915 -0
  459. data/test/progit/ru/figures-dia/fig0511.dia +1201 -0
  460. data/test/progit/ru/figures-dia/fig0515.dia +1741 -0
  461. data/test/progit/ru/figures-dia/fig0702.dia +851 -0
  462. data/test/progit/ru/figures-dia/fig0703.dia +851 -0
  463. data/test/progit/sr/01-introduction/01-chapter1.markdown +257 -0
  464. data/test/progit/summary.rb +29 -0
  465. data/test/progit/th/01-introduction/01-chapter1.markdown +257 -0
  466. data/test/progit/th/02-git-basics/01-chapter2.markdown +1126 -0
  467. data/test/progit/th/README.md +47 -0
  468. data/test/progit/tr/01-introduction/01-chapter1.markdown +258 -0
  469. data/test/progit/tr/02-git-basics/01-chapter2.markdown +1129 -0
  470. data/test/progit/tr/03-git-branching/01-chapter3.markdown +598 -0
  471. data/test/progit/tr/04-git-server/01-chapter4.markdown +73 -0
  472. data/test/progit/tr/05-distributed-git/01-chapter5.markdown +215 -0
  473. data/test/progit/uk/01-introduction/01-chapter1.markdown +522 -0
  474. data/test/progit/vi/01-introduction/01-chapter1.markdown +259 -0
  475. data/test/progit/vi/02-git-basics/01-chapter2.markdown +1172 -0
  476. data/test/progit/vi/03-git-branching/01-chapter3.markdown +598 -0
  477. data/test/progit/zh-tw/01-introduction/01-chapter1.markdown +259 -0
  478. data/test/progit/zh-tw/02-git-basics/01-chapter2.markdown +1183 -0
  479. data/test/progit/zh-tw/03-git-branching/01-chapter3.markdown +604 -0
  480. data/test/progit/zh-tw/04-git-server/01-chapter4.markdown +866 -0
  481. data/test/progit/zh-tw/05-distributed-git/01-chapter5.markdown +912 -0
  482. data/test/progit/zh-tw/06-git-tools/01-chapter6.markdown +1139 -0
  483. data/test/progit/zh-tw/07-customizing-git/01-chapter7.markdown +932 -0
  484. data/test/progit/zh-tw/08-git-and-other-scms/01-chapter8.markdown +689 -0
  485. data/test/progit/zh-tw/09-git-internals/01-chapter9.markdown +977 -0
  486. data/test/progit/zh/01-introduction/01-chapter1.markdown +259 -0
  487. data/test/progit/zh/02-git-basics/01-chapter2.markdown +1177 -0
  488. data/test/progit/zh/03-git-branching/01-chapter3.markdown +604 -0
  489. data/test/progit/zh/04-git-server/01-chapter4.markdown +866 -0
  490. data/test/progit/zh/05-distributed-git/01-chapter5.markdown +912 -0
  491. data/test/progit/zh/06-git-tools/01-chapter6.markdown +1125 -0
  492. data/test/progit/zh/07-customizing-git/01-chapter7.markdown +935 -0
  493. data/test/progit/zh/08-git-and-other-scms/01-chapter8.markdown +689 -0
  494. data/test/progit/zh/09-git-internals/01-chapter9.markdown +976 -0
  495. data/test/spec_tests.json +4382 -4070
  496. data/test/test_basics.rb +1 -1
  497. data/test/test_helper.rb +1 -0
  498. data/test/test_maliciousness.rb +4 -2
  499. data/test/test_pathological_inputs.rb +31 -30
  500. data/test/test_spec.rb +5 -4
  501. metadata +972 -4
@@ -0,0 +1,261 @@
1
+ # Komme i gang #
2
+
3
+ Dette kapittelet handler om å komme i gang med Git. Vi vil begynne på begynnelsen, ved å fortelle noe om bakgrunnen til versjonskontroll, før vi går over til hvordan du kan få Git til å kjøre på ditt system, og til slutt hvordan man kan sette opp og begynne å arbeide med det. Ved kapittelets slutt burde du kunne forstå hvorfor Git finnes, hvorfor du burde bruke det, og du burde være satt opp til å gjøre det.
4
+
5
+ ## Om versjonskontroll ##
6
+
7
+ Hva er versjonskontroll, og hvorfor burde du bry deg? Versjonskontroll er et system som holder styr på forandringer i en fil, eller et sett av filer, over tid, slik at du kan finne tilbake til spesifikke versjoner senere. Selv om eksemplene i denne boka viser kildekodefiler under versjonskontroll, kan man i realiteten bruke det på alle typer filer på en datamaskin.
8
+
9
+ Er du en grafisk designer eller arbeider med webdesign og ønsker å beholde alle versjoner av et bilde eller en layout (som du sannsynligvis vil), så er det lurt å bruke et Version Control System (VCS). Et VCS gjør det mulig for deg å: tilbakestille filer til en tidligere utgave, tilbakestille hele prosjektet til en tidligere utgave, sjekke forandringer over tid, se hvem som sist forandret noe som muligens forårsaker et problem, hvem som introduserte en sak og når, osv. Å benytte seg av et VCS betyr også at dersom du roter det til eller mister filer, kan du vanligvis komme tilbake opp å kjøre raskt og enkelt. I tillegg, så får du alt dette uten at det krever noe videre av deg eller systemet ditt.
10
+
11
+ ### Lokalt versjonskontrollsystem ###
12
+
13
+ Mange folks valgte versjonskontrollmetode innebærer å kopiere filer til en annen mappe (kanskje med datomerking hvis de er smarte). Denne tilnærmingen er vanlig, fordi den er enkel, men det kan også fort gå galt. Det er lett å glemme hvilken mappe man befinner seg i og så ved et uhell skrive til feil fil, eller kopiere over filer man ikke mente.
14
+
15
+ For å hanskes med dette problemet utviklet programmerere, for lenge siden, lokale VCSer der en enkel database holdt alle forandringer i filer som var under revisjonskontroll (se Figure 1-1).
16
+
17
+ Insert 18333fig0101.png
18
+ Figure 1-1. Lokalt versjonskontrolldiagram.
19
+
20
+ Et av de mer populære VCS-verktøyene var et system kalt rcs, som fremdeles distribueres med mange datamaskiner i dag. Selv det populære Mac OS X-operativsystemet inkluderer rcs-kommandoen når en installerer utviklerverktøyene. Dette verktøyet virker, enkelt fortalt, ved å beholde et sett av patcher (dvs, forskjellen mellom filene) fra en revisjon til en annen, i et spesielt format på disken; det kan så gjenskape hvordan enhver fil så ut på et hvilket som helst tidspunkt, ved å legge sammen alle patchene.
21
+
22
+ ### Sentraliserte Versjonkontrol Systemer ###
23
+
24
+ Det neste store problemet folk møter er at de trenger å sammarbeide med utviklere på andre systemer. For å håndere det problemet så var Sentraliserte Versjonkontrol Systmer (CVCSer) utviklet. Disse systemene, som CVS, Subversion, og Perforce, har en ekelt server som inneholder alle versjonerte filer, og tallvis med klienter som sjekker ut filene fra det sentrale stedet. I mange år så har det vært standard for versjonkontrol (Se Figur 1-2).
25
+
26
+ Insert 18333fig0102.png
27
+ Figure 1-2. Sentralisert versjonkontroll diagram.
28
+
29
+ Dette oppsettet tilbyr mange fordeler, spesielt over lokal VCS. For eksempel, alle vet til en viss grad hva alle andre i prosjektet gjør. Administratorer har god kontroll over hvem som kan gjøre hva; og det er langt enklere å administrere en CVCS enn det er å jobbe med lokale databaser på alle klienter.
30
+
31
+ Dette oppsettet har også noen seriøse ulemper. Det mest opplagte er det enkelte punktet for feiling som den sentraliserte serven representere. Hvis den serveren er nede i en time, så kan ingen samarbeide i det hele tatt, eller lagre versjon endringer for noe som helst de jobber på i løpet av den timen. Hvis harddisken den sentraliserte databasen er på blir korrupt, og skikkelige backuper ikke har blir lagt, så vil du miste alt- hele historien til prosjektet med untak i hvilket nå enn enkle bildet folk har akkurat da på deres lokale maskiner. Lokale VCS systmer lider fra det samme problemet, når du har hele historien til prosjeket på ett sted, så risikerer du å miste alt.
32
+
33
+ ### Distribuerte versjonkontrollsystemer ###
34
+
35
+ Her er det Distribuerte Versjonkontrollsystemer (DVCSer) komme inn. I et DVCS (slik som Git, Mercurial, Bazaar eller Darcs), så henter ikke klientene bare ut det nyeste bildet av filene: de speilere hele repositoriet. Så derfor, om en server skulle dø, og disse systemene samarbeidet via den, så kan hvilken som helst av klient repositoriene bli kopiert opp til serveren for å fikse det. Hver utsjekking er en hel backup av alle dataene (see Figure 1-3).
36
+
37
+ Insert 18333fig0103.png
38
+ Figure 1-3. Distributed version control diagram.
39
+
40
+ Mange av disse systemene håndterer også veldig godt det å ha flere fjerne repositorier å jobbe mot, sq du kan sammarbeide med flere forskjellige grupper folk på forskjellige måter samtidig innen for det samme prosjektet. Dette lar deg sette opp flere arbeidsmåter som ikke er mulig i sentraliserte systemer, som hierarkiske modeller.
41
+
42
+ ## Kort Historie om Git ##
43
+
44
+ Som mange flotte ting i livet, så begynte Git med litt kreativ ødeleggelse og voldsom uenighet. Linux kjernen er et åpenkildekode prosjekt ved en ganske vidt skop. Mesteparten av livet til Linux kjerne vedlikeholdet (1991-2002), så var endringer i programvaren sendt rundt som patcher og arkiverte filer. I 2002 begynte Linux kjerne prosjektet å bruke et proprietært DVCS system med navn BitKeeper.
45
+
46
+ I 2005 så falt forholdet mellom samholdet som utviklet Linux-kjernen og det komersielle firmaet som utviklet Bitkeeper sammen, og verktøyets gratis-bruk status ble fjernet. Dette fikk Linux utviklingssamholdet (og spesielt Linux Torvals, skaperen av Linux) til å utvikle deres eget verktøy med grunnlag i noen av tingene de lærte mens de brukte BitKeeper. Noen av målene for det nye systemet ble som følger:
47
+
48
+ * Fart
49
+ * Enkelt design
50
+ * Sterk støtter for ikke-lineær utvikling (tusenvis av parallelle grener)
51
+ * Helt distribuert
52
+ * Able to handle large projects like the Linux kernel efficiently (speed and data size)
53
+ * I stand til å håndtere store prosjekter som Linux-kjernern effektivt (fart og datastørrelse)
54
+
55
+ Siden den ble skapt i 2005, har Git utviklet seg og modnet til å bli et enkelt å bruke men forsatt beholde disse opprinnelige kvalitetene. Den er er utrolig rask, og den er veldig effektiv med store prosjekter, og den har et utrolig avgreningsystem for ikke-lineær utvikling (See Chapter 3).
56
+
57
+ ## Grunnleggende Git ##
58
+
59
+ Så, hva er Git i et nøtteskall? Dette er en veldig viktig seksjon og ta innover seg, fordi om du forstår hva Git er og det fundamentelle rundt hvordan det virker, så vil det å bruke Git effektiv, sannsynligvis bli mye enklere for deg. Etter som du lærer Git, prøv å tøm tankene for de tingene du vet om andre VCSer, som Subversion og Perforce; å gjøre det vil hjelpe deg å unngå småforvirring når du bruker verktøyet. Git lagrer og tenker på informasjon veldig annerledes disse andre systemene, selv om bruker grensesnittet er ganske likt; å forstå de forskjellene vil hjelpe deg unngå å bli forvirret mens du bruker det.
60
+
61
+
62
+ ### Bilder, Ikke Forskjeller ###
63
+
64
+ Hovedforskjellen mellom Git og andre VCS verktøy (inklusivt Subversion og dens venner) er hvordan den tenker på sin data. Konseptuelt, så lagrer de fleste andre systemer informasjon som en liste over filbaserte endringer. Disse systemene (CVS, Subversion, Perforce, Bazaar, og så vidre) tenker på informasjon som det tar vare på som et sett med filer og endringene gjort til hver fil over tid, som illustrert i Figur 1-4.
65
+
66
+ Insert 18333fig0104.png
67
+ Figure 1-4. Andre systemer pleier å lagre data som endringer til en grunnleggende versjon av hver fil.
68
+
69
+ Git verken tenker eller lagrere dataen på denne måten. Istedet så tenker Git på dataen mer som et sett med bilder av mini filsystemer. Hver gang du commit-er, eller lagrere tilstanden for prosjektet ditt i Git, så tar den i hovedask et bilde av hvordan alle filene dine ser ut i det øyeblikket of lagrer en referanse til det bildet. For å være effektiv, hvis filer ikke har blitt endre, så lagrer ikke Git filen igjen, den bare linker til forrige indentiske fil som den allerede har lagret. Git tenker på dataen mer som Figure 1-5.
70
+
71
+ Insert 18333fig0105.png
72
+ Figure 1-5. Git lagrere data som et bilde av prosjektet over tid.
73
+
74
+ Dette er et viktig skille mellom Git og nesten alle andre VCSer. Det gjør at Git revurderer nesten alle aspekter av versjonkontroll som de fleste andre systemer kopierte fra den forrige generasjonen. Dette gjør Git mer til et mini-filsystem som har utrolig kraftige verktøy bygd oppå seg, istedet for bare en VCS. Vi vil utforske noen av fordelene du vil få ved å tenke på dataen din på denne måten når vi dekker Git avgrening i Kapitell 3.
75
+
76
+ ### Nærmest Alle Operasjoner Er Lokale ###
77
+
78
+ De fleste operasjonene i Git trenger bare lokale filer og resurser for å operer - generelt sett så er ikke informasjon fra noen annen maskin på nettverket ditt nødvendig. Hvis du har brukt en CVCS hvor de fleste operasjoner har den type nettverk forsinkelse, så vil dette aspektet av Git få deg til å tenke at gudene for fart har velsignet Git med uparallelle krefter. Fordi du har hele historien til prosjektet rett der på den lokale disk, så virker de fleste operasjoner som om de nesten skjer med en gang.
79
+
80
+ For eksempel, for å se gjennom historien til prosjektet, så trenger ikke Git å gå til serveren for å få historien, og vise det til deg- den simpelthen leser den rett fra din likale database. Dette betyr at du ser prosjekt historien nesten med en gang. Hvis du ønsker å se endringene introdusert mellom den nåværende versjonen av filen og filen for en måned isden, så kan Git sjekke den filen fra en måned siden og gjøre en lokal forskjell kalkulasjon, istedet for å enten måtte spøre en server om å gjøre det, eller å måtte hente en eldre versjon av filen fra den serveren for å gjøre det lokalt.
81
+
82
+ Dette betyr også at det er veldig lite du ikke kan gære om du er offline eller ikke er på VPN. Du kan gå på et fly, eller et tog og så ønske å jobbe litt, og du kan gladelig comitte det fram til du kommer til en nettverkstilkobling for å laste det opp. Hvis du går hjem og ikke kan få VPN klienten til å virke skikkelig, så kan du fortsatt jobbe. I mange systemer, så er det enten umulig å gjøre, eller smertefult. I Perforce, for eksempel, så kan du ikke gjære stort når du ikke er koblet til serveren, og i Subversion og CVS, så kan du endre filer, men du kan ikke bruke commit på endringene dine til databasen (siden databasen din er offline). Dette virker kanskje ikke som noe stort, men du kan bli overrasket over hvor stor forskjell det kan utgjøre.
83
+
84
+ ### Git Har Integritet ###
85
+
86
+ Alt i Git er sjekksummert før det er lagret, og så blir den referert til med den sjekksummen. Dette betyr at det umulig å endre innhodlet på en fil eller mappe uten at Git vet om det. Denne funksjonaliteten er bygd inn i Git på de laveste nivåene og er viktig del av dens filosofi. Du kan ikke miste informasjon når den prossesserer endringer eller ende opp med en korrupt fil uten at Git er i stand til å oppdage det.
87
+
88
+ Mekanismen Git bruker for denne sjekksummeringen er kalt en SHA-1 hash. Dette er en 40-tegn lang tekst satt sammen av hexadecimal-tegn (0-9 og a-f) og er kalkulert baser på innholdet av en fil og mappe structuren i Git. En SHA-1 hash ser ut noe sånt som dette:
89
+
90
+ 24b9da6552252987aa493b52f8696cd6d3b00373
91
+
92
+ Du vil se disse hash verdiene overalt i Git fordi den bruker dem så mye. Git lagrer faktisk alt, ikke med navn, men i Git databasen adresserbart med hash verdien av innholdet dens.
93
+
94
+ ### Git Legger Generelt Bare Til Data ###
95
+
96
+ Når du gjør ting i Git, så vil nesten alle bare legge til data til Git databasen. Det er veldig vanskelig å få systemet til å gjøre noe som ikke kan angres, eller få det til å slette data på en eller annen måte. Som i en hver VCS, så kan du miste eller rote til endringer du ikke har commitet enda; men etter du har commited et bilde inn i Git, så er det veldig vanskelig å miste det, spesielt om du jevnlig bruker push for å sende databasen til en annen repository.
97
+
98
+ Dette gjør det å bruke Git til en gledelig opplevelse fordi vi vet at vi kan eksperimentere uten fare for å virkelig rote til ting skikkelig. For en mer dypere innsyn i hvoradn Git lagerer data og hvordan du kan få tilbake data som virker tapt, se Kapitel 9.
99
+
100
+ ### De Tre Tilstandene ###
101
+
102
+ Følg med. Detter er viktigeste å huske om Git om du ønsker at resten av læringsprossessen din skal gå flytende. Git har tre hoved tilstandet som filene dine kan være i: committed, modified, og staged. Commited betyr at dataen er laget trygt i din lokale database. Mofigied betyr at du har endret på filen men ikke har committed den til databasen enda. Staged betyr at du har markert en modified fil i dens nåværende versjon til å gå inn i ditt neste commit bilde.
103
+
104
+ This leads us to the three main sections of a Git project: the Git directory, the working directory, and the staging area.
105
+
106
+ Insert 18333fig0106.png
107
+ Figure 1-6. Arbeidsmappe, staging området, og git mappe.
108
+
109
+ Git mappen er der Git lagere metadata og objekt databasen for prosjektet ditt. Dette er den mest viktige delen av Git, og det er det som er kopier når du kloner et repository fra en annen maskin.
110
+
111
+ Arbeidsmappen er en enkel checkout av en versjon av prosjektet. Disse filene er dratt ut av den komprimerte databasen i Git mappen og plassert på disken slik at du kan bruke eller modifisere det.
112
+
113
+ Staging området er en enkelt fil, generelt holdt i Git mappen din, som lagrer informasjon om hva som vil gå inn i din neste commit. Det er noen ganger referert til som indeksen, men det begynner å bli det vanlige å kalle det staging området.
114
+
115
+ Den grunnleggende Git arbeidsmåten er litt som dette:
116
+
117
+ 1. Du modifiserer filer i arbeidmappa.
118
+ 2. Du stage-er filene, og lager bilder av den til staging området.
119
+ 3. Du gjør en commit, som tar filene som de er i staging området og lagrer det bildet permanent i Git mappen din.
120
+
121
+ Hvis en bestemt versjon av en fil er i git mappen, så er den ansett som comitted. Hvis den er modifisert men har blitt lagt til i staging området, så der den staged. Og hvis den var endret siden den var sjekket ut men ikke blitt staged, så er den modifisert. I Kapitel 2 så vil du lære om disse tilstande og hvordan du kan utnytte deg av dem eller hoppe over staged-delen helt.
122
+
123
+ ## Installer Git ##
124
+
125
+ La oss gå inn for å bruke litt Git. Det første du trenger gjøre er å installere det. Du kan gjøre det på flere måter; de to vanlige er å installere det fra kildekode eller å installere en allerede eksisterende pakke for din platform.
126
+
127
+ ### Installere fra Kildekode ###
128
+
129
+ Hvis du kan, så er det generelt sett nyttig å installere Git fra kildekode, ettersom du vil få nyeste versjon. Hver versjon av Git pleier å inkludere nyttige grensensitt forbedringer, så å skaffe seg den nyeste versjonen er ofte den beste måten, dersom du føler deg komfortable med å kompilere programvare fra kildekode. Det er er også tilfellet at mange Linux distrobusjoner har veldig gamle pakker; så med mindre du er på en veldig up-to-date distro eller bruker backports, så er det å installere fra kildekode den beste løsningen.
130
+
131
+ For å installere git så trenger du følgene biblioteker som Git er avhengige av: curl, zlib, openssl, expat, and libiconv. For eksempel, om du er på et system som har yum (som Fedora) eller apt-get (som Debian baserte systemer), så kan du bruke en av disse kommandoene for å installere alle avhengighetene:
132
+
133
+ $ yum install curl-devel expat-devel gettext-devel \
134
+ openssl-devel zlib-devel
135
+
136
+ $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
137
+ libz-dev libssl-dev
138
+
139
+ Når du har alle de nødvendige avhengighetene, så kan du gå å laste det nyeste bildet fra Git nettsiden:
140
+
141
+ http://git-scm.com/download
142
+
143
+ Og så, kompiler og installer:
144
+
145
+ $ tar -zxf git-1.7.2.2.tar.gz
146
+ $ cd git-1.7.2.2
147
+ $ make prefix=/usr/local all
148
+ $ sudo make prefix=/usr/local install
149
+
150
+ Etter alt dette er gjort, så kan du også få Git gjennom Git for oppdateringer.
151
+
152
+ $ git clone git://git.kernel.org/pub/scm/git/git.git
153
+
154
+ ### Installer på Linux ###
155
+
156
+ Hvis du vil installere Git på Linux via en binær installasjonspakke, så kan du generelt få gjort det gjennom det vanlige pakkebehandlerverktøyet som kommer med distroen din. Hiv du er på Fedora, så kan du bruke yum:
157
+
158
+ $ yum install git-core
159
+
160
+ Eller om du bruker en Debian-basert distro som Ubuntu, prøv apt-get:
161
+
162
+ $ apt-get install git
163
+
164
+ ### Installer på Mac ###
165
+
166
+ Det er to enkle måter å installere Git på en Mac. Den enkleste er å bruke den grafiske Git installasjonspakken, som du kan laste ned fra SourceForge siden (se Figur 1-7):
167
+
168
+ http://sourceforge.net/projects/git-osx-installer/
169
+
170
+ Insert 18333fig0107.png
171
+ Figure 1-7. Git OS X innstallasjon.
172
+
173
+ Den andre vanlige måten å gjære det på er å installere Git via MacPorts ('http://macports.org'). Hvis du har MacPorts installert, installer Git med
174
+
175
+ $ sudo port install git-core +svn +doc +bash_completion +gitweb
176
+
177
+ Du trenger ikke alt det ekstra, men du vil sannynligvis ønske å inkludere +svn sånn i fall du trenger å bruke git med Subversion repositorier (se Kapitel 8).
178
+
179
+ ### Installer på Windows ###
180
+
181
+ Å installere Git på Windows er veldig enkelt. msysGit prosjektet har en av de enkleste installasjonprossedyrene. Bare last ned installasjons exe filen fra GitHub siden, og kjær den:
182
+
183
+ http://msysgit.github.com/
184
+
185
+ Etter den er installert, så har du både en kommandolinje versjon (inkludert en SSH klient som vil bli nyttig senere) og det standard grafiske brukgergrensesnittet.
186
+
187
+ Merknad om Windows bruk: du burde bruke Git med msysGit shellet (Unix stil) som kommer med, det lar deg bruke de komplekse linjene med kommandoer gitt i denne boken. Om du av en eller annen grunn skulle trenge å bruke Windows sitt eget shell/kommandolinje konsoll, så må du bruker dobbelt annførsel tegn istedet for enkelt annførselstegn (for parametere med mellomrom i seg) og du må bruke annførseltegn på parametere som slutter med ^ om de er på slutten av linjen, siden det er et forsettelsesymbol i Windows.
188
+
189
+ ## Git Oppsett For Førstegangsbruk ##
190
+
191
+ Nå som du har Git på systemet ditt, så vil du ønske å gjøre noen få endringer for Git miljøet ditt. Du burder bare trenge å gjøre disse tingene en gang; for de blir værende med deg mellom oppgraderinger. Du kan også endre dem når som helst ved å gå gjennom kommandoene igjen.
192
+
193
+ Git kommer med et verktøy kalt git config som lar deg hente og sette instillingvariabler som kontrollerer alle aspektene av hvoran Git ser ut og virker. Disse varaiblene kan bli lagret i tre forskjellige steder:
194
+
195
+ * `/etc/gitconfig` filen: Inneholder verdier for alle brukerene på systemet og alle repositoriene deres. Hvis du sender valget `--system` til `git config`, så vil det lese og skrives i denne filen.
196
+ * `~/.gitconfig` filen: Spesifikk for brukeren. Du kan får Git til å lese og skrive til denne filen ved å sende `--global` valget.
197
+ * config filen i git mappen (altså `.git/config`) av hvilken som helst repository du bruker for øyeblikket: Brukes for det enkelte repositoriet. Hver nivå overstyrer verdiene fra forrige nivå, så verdiene i `.git/config` trumfer de som er i `/etc/gitconfig`.
198
+
199
+ På Windows systemer så ser Git etter `.gitconfig`filen i `$HOME` mappen (`%USERPROFILE%` for Windows), som er `C:\Documents and Settings\$USER` eller `C:\Users\$User` for de fleste, avhengig av versjon (`$USER` er `%USERNAME%` i Windows). Det ser forsatt etter /etc/gitconfig/, selv om det er relativt til MSys root, som er hvor du la inn Git for Windows systemet når du installerte det.
200
+
201
+ ### Din Identitet ###
202
+
203
+ Det første du burde gjøre når du installerer Git er å sette brukernavnet og email-addressen din. Dette er viktig fordig alle Git commiter bruker denne informasjonen, og det er uforanderlig integrert inn i commitene du sender rundt.
204
+
205
+ $ git config --global user.name "John Doe"
206
+ $ git config --global user.email johndoe@example.com
207
+
208
+ Igjen, så trenger du bare å gjøre dette en gang om du bruker `--global` valget, siden Git alltid bruker den informasjonen for alt du gjør på det systemet. Hvis du ønsker å overstyre dette med ett annet navn eller email-adresse for bestemte prosjekter, så kan du kjøre kommandoen uten `--global` valget når du er i det prosjektet.
209
+
210
+ ### Din Editor ###
211
+
212
+ Nå som din identiter er satt opp, så kan du konfigurere den forhåndsvalgte tekst editoren som vil bli brukt når Git trenger at du skriver en beskjed. Forhåndsvalget satt i Git bruker systemets forhåndsvalgte editor, som generelt sett er Vi eller Vim. Hvis du ønsker å bruke en annen tekst editor, som Emacs, så kan du gjøre følgende:
213
+
214
+ $ git config --global core.editor emacs
215
+
216
+ ### Ditt Diff Verktøy ###
217
+
218
+ Et annet nyttig valg du kanskje vil endre på er forhåndsvalgt diff verktøy for å bruke til å håndtere merge konflikter. Så si du ønsker å bruke vimdiff:
219
+
220
+ $ git config --global merge.tool vimdiff
221
+
222
+ Git godtar kdiff3, tkdiff, meld, xxdif, emerge, vimdiff, gvimdiff, ecmerge, and opendiff som godkjente merge verktøy. Du kan også sette opp et eget verktøy; se Kapitel 7 for mer informasjon om hvordan gjøre det.
223
+
224
+ ### Sjekke Innstillingene Dine ###
225
+
226
+ Hvis du ænsker å sjekke innstillingene dine, så kan du bruke `git config --list` kommandoen for å liste alle innstillingene Git kan finne akkurat da:
227
+
228
+ $ git config --list
229
+ user.name=Scott Chacon
230
+ user.email=schacon@gmail.com
231
+ color.status=auto
232
+ color.branch=auto
233
+ color.interactive=auto
234
+ color.diff=auto
235
+ ...
236
+
237
+ Du kan se nøkler mer enn en gang, siden Git leser den samme nøkkelen fra forskjellige filer (`/etc/gitconfig` og `~/.gitconfig`, for eksempel). I såfall, så bruker Git den siste verdien for hver unike nøkkel den ser.
238
+
239
+ Du kan også sjekke hva Git tror en spesifikk nøkkels verdi er ved å skrive `git config {nøkkel}`:
240
+
241
+ $ git config user.name
242
+ Scott Chacon
243
+
244
+ ## Skaffe Seg Hjelp ##
245
+
246
+ Hvis du noen gang trenger hjelp mens du bruker Git, så er det tre måter å få manual sidens (manpage) hjelp for en hvilken som helst Git kommando:
247
+
248
+ $ git help <verb>
249
+ $ git <verb> --help
250
+ $ man git-<verb>
251
+
252
+ For eksempel, du kan få manpage hjelp ved for config kommandoen ved å bruke
253
+
254
+ $ git help config
255
+
256
+ Disse kommandoene er fine fordi du kan få tilgang til dem over alt, tilogmed offline.
257
+ Hvis manpagene og denne boken ikke er nok, og du trenger hjelp fra folk, så kan du prøve `#git` eller `#github` kanalene på Freenode IRC Server (irc.freenode.net). Disse kanalene er til vanlig fylt med hundrevis av folk som alle kan veldig mye om Git og er ofte villige til å hjelpe.
258
+
259
+ ## Sammendrag ##
260
+
261
+ Du burde ha grunnleggende forståelse for hva Git er og hvordan det skiller seg fra CVCSene du kan ha brukt. Du burde også nå ha en funksjonell versjon av Git på ditt system som er satt opp med din personlige identitet. Det er nå på tide å lære litt grunnleggende Git.
@@ -0,0 +1,1225 @@
1
+ # Grunnleggende Git #
2
+
3
+ Om du bare kan lese et kapitel for å komme i gang med Git, så er dette det kapitelet. Dette kapitellet dekker hver grunnlegende kommando du trenger for å gjøre største delen av ting du etterhvert vil bruke tiden din på å gjøre i Git. Ved slutten av dette kapitelet, så burde du være istand til å konfigurere og initiere et repository, begynne og stoppe overvåking av filer, og stage og commite endringer. Vi vil også vise deg hvordan sette opp Git til å ignorere visse filer og filmønstre, hvordan angre på feil fort og enkelt, hvordan se gjennom historien for prosjektet ditt og se på endringer mellom commiter, og hvordan pushe(dytte) endringer til eller pulle(dra) endringer fra en fjern repository.
4
+
5
+ ## Skaffe seg et Git Repository ##
6
+
7
+ Du kan skaffe deg et Git prosjekt ved å bruke to hovedframganger. Den første tar et eksisterende prosjekt eller mappe og importerer det inn i Git. Den andre kloner et eksisterende Git repository fra en annen server.
8
+
9
+ ### Initere et Repository i en Eksisterende Mappe ###
10
+
11
+ Om du begynner å spore et eksisterende prosjekt i Git, så trenger du å gå inn i projektets mappe og skrive
12
+
13
+ $ git init
14
+
15
+ Dette lager en ny undermappe kalt `.git` som inneholder alle dine nødvendige repository filer – et Git repository skjellet. På dette tidspunktet, så er ingenting i prosjektet ditt overvåket enda. (See *Kapitel 9* for mer informasjon om nøyaktig hvile filer som finnes i `.git`mappen du akkurat lagde.)
16
+
17
+ Om du ønsker å starte versjonkontroll på eksisterende filer (imotsetning til en tom mappe), så burde du sannsynligvis begynne å overvåke de filene og gjøre en første commit. Du kan gjøre det med noen få `git add` kommandoer som spesifiserer filene du ønsker å overvåke, fulgt med en commit:
18
+
19
+ $ git add *.c
20
+ $ git add README
21
+ $ git commit -m 'initial project version'
22
+
23
+ Vi vil gå over hva disse kommandoene gjør straks. Nå har du et Git repository med overvåkedne filer og en første kommit.
24
+
25
+ ### Klone et Eksistrende Repository ###
26
+
27
+ Hvis du ænsker å hente en kopi av et eksisterende Git repository, for eksempel, et prosjekt du gjerne vil bidra til, så er kommandoen du trenger `git clone`. Hvis du er kjent med andre VCS systemer som Subversion, så vil du legge merke til at kommandoen er `clone`ikke `checkout`. Dette er en viktig forskjell. Git mottar en kopi av nesten all data som serveren har. Hver version av en hver fil i løpet av prosjektet historie vil bli dratt ned når du kjører `git clone`. Om server disken blir korrupt, så kan du bruke hvilken som helst av klonene på en hvilken som helst klient for å sette til tilstanden den var i når den var klonet (du mister kanskje noen hook-er og slikt på server siden , men all den versjonerte dataen ville vært der. Se *Kapitel 4* for mer detaljer).
28
+
29
+ Du kloner et repository med `git clone [url]`. For eksempel, hvis du ænsker å klone Ruby Git biblioteket kalt Grit, så kan du gjøre det slik:
30
+
31
+ $ git clone git://github.com/schacon/grit.git
32
+
33
+ Det lager en mappe kalt `grit`, initierer en `.git` mappe inni den, og drar ned all dataen fra det repositoriet, og sjekker ut en funksjonell kopi av den nyeste versjonen. Hvis du går inn i den nye `grit`mappen, så vil du se prosjekt filer inni den, klar til å bli bearbeidet eller brukt. Om du ønsker å klone repositoriet inn i en annen mappe kalt noe annet enn grit, så kan du spesifisere det som det neste kommandolinje valget.
34
+
35
+ $ git clone git://github.com/schacon/grit.git mygrit
36
+
37
+ Den kommandoen gjør det samme som den forrige, bare at målmappen blir kalt `mygrit`.
38
+
39
+ Git har tallvis av forskjellige overgangprotokoller du kan bruke. Det forrige eksemplet bruker `git://`-protokollen , men du ser kanskje også `http(s)://` eller `user@server:/path.gti`, som bruker SSH overganprotokollen. *Kapitel 4* vil introdusere alle de tilgjenglige valgene serveren kan sette opp for å gi tilgang til ditt Git repository og fordelen og ulempen med hver av dem.
40
+
41
+ ## Recording Changes to the Repository ##
42
+
43
+ You have a bona fide Git repository and a checkout or working copy of the files for that project. You need to make some changes and commit snapshots of those changes into your repository each time the project reaches a state you want to record.
44
+
45
+ Remember that each file in your working directory can be in one of two states: *tracked* or *untracked*. *Tracked* files are files that were in the last snapshot; they can be *unmodified*, *modified*, or *staged*. *Untracked* files are everything else — any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.
46
+
47
+ As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You *stage* these modified files and then commit all your staged changes, and the cycle repeats. This lifecycle is illustrated in Figure 2-1.
48
+
49
+ Insert 18333fig0201.png
50
+ Figure 2-1. The lifecycle of the status of your files.
51
+
52
+ ### Checking the Status of Your Files ###
53
+
54
+ The main tool you use to determine which files are in which state is the `git status` command. If you run this command directly after a clone, you should see something like this:
55
+
56
+ $ git status
57
+ On branch master
58
+ nothing to commit, working directory clean
59
+
60
+ This means you have a clean working directory — in other words, no tracked files are modified. Git also doesn’t see any untracked files, or they would be listed here. Finally, the command tells you which branch you’re on. For now, that is always `master`, which is the default; you won’t worry about it here. The next chapter will go over branches and references in detail.
61
+
62
+ Let’s say you add a new file to your project, a simple `README` file. If the file didn’t exist before, and you run `git status`, you see your untracked file like so:
63
+
64
+ $ vim README
65
+ $ git status
66
+ On branch master
67
+ Untracked files:
68
+ (use "git add <file>..." to include in what will be committed)
69
+
70
+ README
71
+
72
+ nothing added to commit but untracked files present (use "git add" to track)
73
+
74
+ You can see that your new `README` file is untracked, because it’s under the “Untracked files” heading in your status output. Untracked basically means that Git sees a file you didn’t have in the previous snapshot (commit); Git won’t start including it in your commit snapshots until you explicitly tell it to do so. It does this so you don’t accidentally begin including generated binary files or other files that you did not mean to include. You do want to start including README, so let’s start tracking the file.
75
+
76
+ ### Tracking New Files ###
77
+
78
+ In order to begin tracking a new file, you use the command `git add`. To begin tracking the `README` file, you can run this:
79
+
80
+ $ git add README
81
+
82
+ If you run your status command again, you can see that your `README` file is now tracked and staged:
83
+
84
+ $ git status
85
+ On branch master
86
+ Changes to be committed:
87
+ (use "git reset HEAD <file>..." to unstage)
88
+
89
+ new file: README
90
+
91
+
92
+ You can tell that it’s staged because it’s under the “Changes to be committed” heading. If you commit at this point, the version of the file at the time you ran `git add` is what will be in the historical snapshot. You may recall that when you ran `git init` earlier, you then ran `git add (files)` — that was to begin tracking files in your directory. The `git add` command takes a path name for either a file or a directory; if it’s a directory, the command adds all the files in that directory recursively.
93
+
94
+ ### Staging Modified Files ###
95
+
96
+ Let’s change a file that was already tracked. If you change a previously tracked file called `benchmarks.rb` and then run your `status` command again, you get something that looks like this:
97
+
98
+ $ git status
99
+ On branch master
100
+ Changes to be committed:
101
+ (use "git reset HEAD <file>..." to unstage)
102
+
103
+ new file: README
104
+
105
+ Changes not staged for commit:
106
+ (use "git add <file>..." to update what will be committed)
107
+ (use "git checkout -- <file>..." to discard changes in working directory)
108
+
109
+ modified: benchmarks.rb
110
+
111
+
112
+ The `benchmarks.rb` file appears under a section named “Changes not staged for commit” — which means that a file that is tracked has been modified in the working directory but not yet staged. To stage it, you run the `git add` command (it’s a multipurpose command — you use it to begin tracking new files, to stage files, and to do other things like marking merge-conflicted files as resolved). Let’s run `git add` now to stage the `benchmarks.rb` file, and then run `git status` again:
113
+
114
+ $ git add benchmarks.rb
115
+ $ git status
116
+ On branch master
117
+ Changes to be committed:
118
+ (use "git reset HEAD <file>..." to unstage)
119
+
120
+ new file: README
121
+ modified: benchmarks.rb
122
+
123
+
124
+ Both files are staged and will go into your next commit. At this point, suppose you remember one little change that you want to make in `benchmarks.rb` before you commit it. You open it again and make that change, and you’re ready to commit. However, let’s run `git status` one more time:
125
+
126
+ $ vim benchmarks.rb
127
+ $ git status
128
+ On branch master
129
+ Changes to be committed:
130
+ (use "git reset HEAD <file>..." to unstage)
131
+
132
+ new file: README
133
+ modified: benchmarks.rb
134
+
135
+ Changes not staged for commit:
136
+ (use "git add <file>..." to update what will be committed)
137
+ (use "git checkout -- <file>..." to discard changes in working directory)
138
+
139
+ modified: benchmarks.rb
140
+
141
+
142
+ What the heck? Now `benchmarks.rb` is listed as both staged and unstaged. How is that possible? It turns out that Git stages a file exactly as it is when you run the `git add` command. If you commit now, the version of `benchmarks.rb` as it was when you last ran the `git add` command is how it will go into the commit, not the version of the file as it looks in your working directory when you run `git commit`. If you modify a file after you run `git add`, you have to run `git add` again to stage the latest version of the file:
143
+
144
+ $ git add benchmarks.rb
145
+ $ git status
146
+ On branch master
147
+ Changes to be committed:
148
+ (use "git reset HEAD <file>..." to unstage)
149
+
150
+ new file: README
151
+ modified: benchmarks.rb
152
+
153
+
154
+ ### Ignoring Files ###
155
+
156
+ Often, you’ll have a class of files that you don’t want Git to automatically add or even show you as being untracked. These are generally automatically generated files such as log files or files produced by your build system. In such cases, you can create a file listing patterns to match them named `.gitignore`. Here is an example `.gitignore` file:
157
+
158
+ $ cat .gitignore
159
+ *.[oa]
160
+ *~
161
+
162
+ The first line tells Git to ignore any files ending in `.o` or `.a` — *object* and *archive* files that may be the product of building your code. The second line tells Git to ignore all files that end with a tilde (`~`), which is used by many text editors such as Emacs to mark temporary files. You may also include a `log`, `tmp`, or `pid` directory; automatically generated documentation; and so on. Setting up a `.gitignore` file before you get going is generally a good idea so you don’t accidentally commit files that you really don’t want in your Git repository.
163
+
164
+ The rules for the patterns you can put in the `.gitignore` file are as follows:
165
+
166
+ * Blank lines or lines starting with `#` are ignored.
167
+ * Standard glob patterns work.
168
+ * You can end patterns with a forward slash (`/`) to specify a directory.
169
+ * You can negate a pattern by starting it with an exclamation point (`!`).
170
+
171
+ Glob patterns are like simplified regular expressions that shells use. An asterisk (`*`) matches zero or more characters; `[abc]` matches any character inside the brackets (in this case `a`, `b`, or `c`); a question mark (`?`) matches a single character; and brackets enclosing characters separated by a hyphen(`[0-9]`) matches any character in the range (in this case 0 through 9) .
172
+
173
+ Here is another example `.gitignore` file:
174
+
175
+ # a comment - this is ignored
176
+ # no .a files
177
+ *.a
178
+ # but do track lib.a, even though you're ignoring .a files above
179
+ !lib.a
180
+ # only ignore the root TODO file, not subdir/TODO
181
+ /TODO
182
+ # ignore all files in the build/ directory
183
+ build/
184
+ # ignore doc/notes.txt, but not doc/server/arch.txt
185
+ doc/*.txt
186
+ # ignore all .txt files in the doc/ directory
187
+ doc/**/*.txt
188
+
189
+ A `**/` pattern is available in Git since version 1.8.2.
190
+
191
+ ### Viewing Your Staged and Unstaged Changes ###
192
+
193
+ If the `git status` command is too vague for you — you want to know exactly what you changed, not just which files were changed — you can use the `git diff` command. We’ll cover `git diff` in more detail later; but you’ll probably use it most often to answer these two questions: What have you changed but not yet staged? And what have you staged that you are about to commit? Although `git status` answers those questions very generally, `git diff` shows you the exact lines added and removed — the patch, as it were.
194
+
195
+ Let’s say you edit and stage the `README` file again and then edit the `benchmarks.rb` file without staging it. If you run your `status` command, you once again see something like this:
196
+
197
+ $ git status
198
+ On branch master
199
+ Changes to be committed:
200
+ (use "git reset HEAD <file>..." to unstage)
201
+
202
+ new file: README
203
+
204
+ Changes not staged for commit:
205
+ (use "git add <file>..." to update what will be committed)
206
+ (use "git checkout -- <file>..." to discard changes in working directory)
207
+
208
+ modified: benchmarks.rb
209
+
210
+
211
+ To see what you’ve changed but not yet staged, type `git diff` with no other arguments:
212
+
213
+ $ git diff
214
+ diff --git a/benchmarks.rb b/benchmarks.rb
215
+ index 3cb747f..da65585 100644
216
+ --- a/benchmarks.rb
217
+ +++ b/benchmarks.rb
218
+ @@ -36,6 +36,10 @@ def main
219
+ @commit.parents[0].parents[0].parents[0]
220
+ end
221
+
222
+ + run_code(x, 'commits 1') do
223
+ + git.commits.size
224
+ + end
225
+ +
226
+ run_code(x, 'commits 2') do
227
+ log = git.commits('master', 15)
228
+ log.size
229
+
230
+ That command compares what is in your working directory with what is in your staging area. The result tells you the changes you’ve made that you haven’t yet staged.
231
+
232
+ If you want to see what you’ve staged that will go into your next commit, you can use `git diff --cached`. (In Git versions 1.6.1 and later, you can also use `git diff --staged`, which may be easier to remember.) This command compares your staged changes to your last commit:
233
+
234
+ $ git diff --cached
235
+ diff --git a/README b/README
236
+ new file mode 100644
237
+ index 0000000..03902a1
238
+ --- /dev/null
239
+ +++ b/README2
240
+ @@ -0,0 +1,5 @@
241
+ +grit
242
+ + by Tom Preston-Werner, Chris Wanstrath
243
+ + http://github.com/mojombo/grit
244
+ +
245
+ +Grit is a Ruby library for extracting information from a Git repository
246
+
247
+ It’s important to note that `git diff` by itself doesn’t show all changes made since your last commit — only changes that are still unstaged. This can be confusing, because if you’ve staged all of your changes, `git diff` will give you no output.
248
+
249
+ For another example, if you stage the `benchmarks.rb` file and then edit it, you can use `git diff` to see the changes in the file that are staged and the changes that are unstaged:
250
+
251
+ $ git add benchmarks.rb
252
+ $ echo '# test line' >> benchmarks.rb
253
+ $ git status
254
+ On branch master
255
+ Changes to be committed:
256
+ (use "git reset HEAD <file>..." to unstage)
257
+
258
+ modified: benchmarks.rb
259
+
260
+ Changes not staged for commit:
261
+ (use "git add <file>..." to update what will be committed)
262
+ (use "git checkout -- <file>..." to discard changes in working directory)
263
+
264
+ modified: benchmarks.rb
265
+
266
+
267
+ Now you can use `git diff` to see what is still unstaged
268
+
269
+ $ git diff
270
+ diff --git a/benchmarks.rb b/benchmarks.rb
271
+ index e445e28..86b2f7c 100644
272
+ --- a/benchmarks.rb
273
+ +++ b/benchmarks.rb
274
+ @@ -127,3 +127,4 @@ end
275
+ main()
276
+
277
+ ##pp Grit::GitRuby.cache_client.stats
278
+ +# test line
279
+
280
+ and `git diff --cached` to see what you’ve staged so far:
281
+
282
+ $ git diff --cached
283
+ diff --git a/benchmarks.rb b/benchmarks.rb
284
+ index 3cb747f..e445e28 100644
285
+ --- a/benchmarks.rb
286
+ +++ b/benchmarks.rb
287
+ @@ -36,6 +36,10 @@ def main
288
+ @commit.parents[0].parents[0].parents[0]
289
+ end
290
+
291
+ + run_code(x, 'commits 1') do
292
+ + git.commits.size
293
+ + end
294
+ +
295
+ run_code(x, 'commits 2') do
296
+ log = git.commits('master', 15)
297
+ log.size
298
+
299
+ ### Committing Your Changes ###
300
+
301
+ Now that your staging area is set up the way you want it, you can commit your changes. Remember that anything that is still unstaged — any files you have created or modified that you haven’t run `git add` on since you edited them — won’t go into this commit. They will stay as modified files on your disk.
302
+ In this case, the last time you ran `git status`, you saw that everything was staged, so you’re ready to commit your changes. The simplest way to commit is to type `git commit`:
303
+
304
+ $ git commit
305
+
306
+ Doing so launches your editor of choice. (This is set by your shell’s `$EDITOR` environment variable — usually vim or emacs, although you can configure it with whatever you want using the `git config --global core.editor` command as you saw in *Chapter 1*).
307
+
308
+ The editor displays the following text (this example is a Vim screen):
309
+
310
+ # Please enter the commit message for your changes. Lines starting
311
+ # with '#' will be ignored, and an empty message aborts the commit.
312
+ # On branch master
313
+ # Changes to be committed:
314
+ # new file: README
315
+ # modified: benchmarks.rb
316
+ #
317
+ ~
318
+ ~
319
+ ~
320
+ ".git/COMMIT_EDITMSG" 10L, 283C
321
+
322
+ You can see that the default commit message contains the latest output of the `git status` command commented out and one empty line on top. You can remove these comments and type your commit message, or you can leave them there to help you remember what you’re committing. (For an even more explicit reminder of what you’ve modified, you can pass the `-v` option to `git commit`. Doing so also puts the diff of your change in the editor so you can see exactly what you did.) When you exit the editor, Git creates your commit with that commit message (with the comments and diff stripped out).
323
+
324
+ Alternatively, you can type your commit message inline with the `commit` command by specifying it after a `-m` flag, like this:
325
+
326
+ $ git commit -m "Story 182: Fix benchmarks for speed"
327
+ [master 463dc4f] Story 182: Fix benchmarks for speed
328
+ 2 files changed, 3 insertions(+)
329
+ create mode 100644 README
330
+
331
+ Now you’ve created your first commit! You can see that the commit has given you some output about itself: which branch you committed to (`master`), what SHA-1 checksum the commit has (`463dc4f`), how many files were changed, and statistics about lines added and removed in the commit.
332
+
333
+ Remember that the commit records the snapshot you set up in your staging area. Anything you didn’t stage is still sitting there modified; you can do another commit to add it to your history. Every time you perform a commit, you’re recording a snapshot of your project that you can revert to or compare to later.
334
+
335
+ ### Skipping the Staging Area ###
336
+
337
+ Although it can be amazingly useful for crafting commits exactly how you want them, the staging area is sometimes a bit more complex than you need in your workflow. If you want to skip the staging area, Git provides a simple shortcut. Providing the `-a` option to the `git commit` command makes Git automatically stage every file that is already tracked before doing the commit, letting you skip the `git add` part:
338
+
339
+ $ git status
340
+ On branch master
341
+ Changes not staged for commit:
342
+ (use "git add <file>..." to update what will be committed)
343
+ (use "git checkout -- <file>..." to discard changes in working directory)
344
+
345
+ modified: benchmarks.rb
346
+
347
+ no changes added to commit (use "git add" and/or "git commit -a")
348
+ $ git commit -a -m 'added new benchmarks'
349
+ [master 83e38c7] added new benchmarks
350
+ 1 files changed, 5 insertions(+)
351
+
352
+ Notice how you don’t have to run `git add` on the `benchmarks.rb` file in this case before you commit.
353
+
354
+ ### Removing Files ###
355
+
356
+ To remove a file from Git, you have to remove it from your tracked files (more accurately, remove it from your staging area) and then commit. The `git rm` command does that and also removes the file from your working directory so you don’t see it as an untracked file next time around.
357
+
358
+ If you simply remove the file from your working directory, it shows up under the “Changes not staged for commit” (that is, _unstaged_) area of your `git status` output:
359
+
360
+ $ rm grit.gemspec
361
+ $ git status
362
+ On branch master
363
+ Changes not staged for commit:
364
+ (use "git add/rm <file>..." to update what will be committed)
365
+ (use "git checkout -- <file>..." to discard changes in working directory)
366
+
367
+ deleted: grit.gemspec
368
+
369
+ no changes added to commit (use "git add" and/or "git commit -a")
370
+
371
+ Then, if you run `git rm`, it stages the file’s removal:
372
+
373
+ $ git rm grit.gemspec
374
+ rm 'grit.gemspec'
375
+ $ git status
376
+ On branch master
377
+ Changes to be committed:
378
+ (use "git reset HEAD <file>..." to unstage)
379
+
380
+ deleted: grit.gemspec
381
+
382
+
383
+ The next time you commit, the file will be gone and no longer tracked. If you modified the file and added it to the index already, you must force the removal with the `-f` option. This is a safety feature to prevent accidental removal of data that hasn’t yet been recorded in a snapshot and that can’t be recovered from Git.
384
+
385
+ Another useful thing you may want to do is to keep the file in your working tree but remove it from your staging area. In other words, you may want to keep the file on your hard drive but not have Git track it anymore. This is particularly useful if you forgot to add something to your `.gitignore` file and accidentally staged it, like a large log file or a bunch of `.a` compiled files. To do this, use the `--cached` option:
386
+
387
+ $ git rm --cached readme.txt
388
+
389
+ You can pass files, directories, and file-glob patterns to the `git rm` command. That means you can do things such as
390
+
391
+ $ git rm log/\*.log
392
+
393
+ Note the backslash (`\`) in front of the `*`. This is necessary because Git does its own filename expansion in addition to your shell’s filename expansion. On Windows with the system console, the backslash must be omitted. This command removes all files that have the `.log` extension in the `log/` directory. Or, you can do something like this:
394
+
395
+ $ git rm \*~
396
+
397
+ This command removes all files that end with `~`.
398
+
399
+ ### Moving Files ###
400
+
401
+ Unlike many other VCS systems, Git doesn’t explicitly track file movement. If you rename a file in Git, no metadata is stored in Git that tells it you renamed the file. However, Git is pretty smart about figuring that out after the fact — we’ll deal with detecting file movement a bit later.
402
+
403
+ Thus it’s a bit confusing that Git has a `mv` command. If you want to rename a file in Git, you can run something like
404
+
405
+ $ git mv file_from file_to
406
+
407
+ and it works fine. In fact, if you run something like this and look at the status, you’ll see that Git considers it a renamed file:
408
+
409
+ $ git mv README README.txt
410
+ $ git status
411
+ On branch master
412
+ Changes to be committed:
413
+ (use "git reset HEAD <file>..." to unstage)
414
+
415
+ renamed: README -> README.txt
416
+
417
+
418
+ However, this is equivalent to running something like this:
419
+
420
+ $ mv README README.txt
421
+ $ git rm README
422
+ $ git add README.txt
423
+
424
+ Git figures out that it’s a rename implicitly, so it doesn’t matter if you rename a file that way or with the `mv` command. The only real difference is that `mv` is one command instead of three — it’s a convenience function. More important, you can use any tool you like to rename a file, and address the add/rm later, before you commit.
425
+
426
+ ## Viewing the Commit History ##
427
+
428
+ After you have created several commits, or if you have cloned a repository with an existing commit history, you’ll probably want to look back to see what has happened. The most basic and powerful tool to do this is the `git log` command.
429
+
430
+ These examples use a very simple project called `simplegit` that I often use for demonstrations. To get the project, run
431
+
432
+ git clone git://github.com/schacon/simplegit-progit.git
433
+
434
+ When you run `git log` in this project, you should get output that looks something like this:
435
+
436
+ $ git log
437
+ commit ca82a6dff817ec66f44342007202690a93763949
438
+ Author: Scott Chacon <schacon@gee-mail.com>
439
+ Date: Mon Mar 17 21:52:11 2008 -0700
440
+
441
+ changed the version number
442
+
443
+ commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
444
+ Author: Scott Chacon <schacon@gee-mail.com>
445
+ Date: Sat Mar 15 16:40:33 2008 -0700
446
+
447
+ removed unnecessary test code
448
+
449
+ commit a11bef06a3f659402fe7563abf99ad00de2209e6
450
+ Author: Scott Chacon <schacon@gee-mail.com>
451
+ Date: Sat Mar 15 10:31:28 2008 -0700
452
+
453
+ first commit
454
+
455
+ By default, with no arguments, `git log` lists the commits made in that repository in reverse chronological order. That is, the most recent commits show up first. As you can see, this command lists each commit with its SHA-1 checksum, the author’s name and e-mail, the date written, and the commit message.
456
+
457
+ A huge number and variety of options to the `git log` command are available to show you exactly what you’re looking for. Here, we’ll show you some of the most-used options.
458
+
459
+ One of the more helpful options is `-p`, which shows the diff introduced in each commit. You can also use `-2`, which limits the output to only the last two entries:
460
+
461
+ $ git log -p -2
462
+ commit ca82a6dff817ec66f44342007202690a93763949
463
+ Author: Scott Chacon <schacon@gee-mail.com>
464
+ Date: Mon Mar 17 21:52:11 2008 -0700
465
+
466
+ changed the version number
467
+
468
+ diff --git a/Rakefile b/Rakefile
469
+ index a874b73..8f94139 100644
470
+ --- a/Rakefile
471
+ +++ b/Rakefile
472
+ @@ -5,5 +5,5 @@ require 'rake/gempackagetask'
473
+ spec = Gem::Specification.new do |s|
474
+ s.name = "simplegit"
475
+ - s.version = "0.1.0"
476
+ + s.version = "0.1.1"
477
+ s.author = "Scott Chacon"
478
+ s.email = "schacon@gee-mail.com
479
+
480
+ commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
481
+ Author: Scott Chacon <schacon@gee-mail.com>
482
+ Date: Sat Mar 15 16:40:33 2008 -0700
483
+
484
+ removed unnecessary test code
485
+
486
+ diff --git a/lib/simplegit.rb b/lib/simplegit.rb
487
+ index a0a60ae..47c6340 100644
488
+ --- a/lib/simplegit.rb
489
+ +++ b/lib/simplegit.rb
490
+ @@ -18,8 +18,3 @@ class SimpleGit
491
+ end
492
+
493
+ end
494
+ -
495
+ -if $0 == __FILE__
496
+ - git = SimpleGit.new
497
+ - puts git.show
498
+ -end
499
+
500
+
501
+ This option displays the same information but with a diff directly following each entry. This is very helpful for code review or to quickly browse what happened during a series of commits that a collaborator has added.
502
+
503
+ Sometimes it's easier to review changes on the word level rather than on the line level. There is a `--word-diff` option available in Git, that you can append to the `git log -p` command to get word diff instead of normal line by line diff. Word diff format is quite useless when applied to source code, but it comes in handy when applied to large text files, like books or your dissertation. Here is an example:
504
+
505
+ $ git log -U1 --word-diff
506
+ commit ca82a6dff817ec66f44342007202690a93763949
507
+ Author: Scott Chacon <schacon@gee-mail.com>
508
+ Date: Mon Mar 17 21:52:11 2008 -0700
509
+
510
+ changed the version number
511
+
512
+ diff --git a/Rakefile b/Rakefile
513
+ index a874b73..8f94139 100644
514
+ --- a/Rakefile
515
+ +++ b/Rakefile
516
+ @@ -7,3 +7,3 @@ spec = Gem::Specification.new do |s|
517
+ s.name = "simplegit"
518
+ s.version = [-"0.1.0"-]{+"0.1.1"+}
519
+ s.author = "Scott Chacon"
520
+
521
+ As you can see, there is no added and removed lines in this output as in a normal diff. Changes are shown inline instead. You can see the added word enclosed in `{+ +}` and removed one enclosed in `[- -]`. You may also want to reduce the usual three lines context in diff output to only one line, as the context is now words, not lines. You can do this with `-U1` as we did in the example above.
522
+
523
+ You can also use a series of summarizing options with `git log`. For example, if you want to see some abbreviated stats for each commit, you can use the `--stat` option:
524
+
525
+ $ git log --stat
526
+ commit ca82a6dff817ec66f44342007202690a93763949
527
+ Author: Scott Chacon <schacon@gee-mail.com>
528
+ Date: Mon Mar 17 21:52:11 2008 -0700
529
+
530
+ changed the version number
531
+
532
+ Rakefile | 2 +-
533
+ 1 file changed, 1 insertion(+), 1 deletion(-)
534
+
535
+ commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
536
+ Author: Scott Chacon <schacon@gee-mail.com>
537
+ Date: Sat Mar 15 16:40:33 2008 -0700
538
+
539
+ removed unnecessary test code
540
+
541
+ lib/simplegit.rb | 5 -----
542
+ 1 file changed, 5 deletions(-)
543
+
544
+ commit a11bef06a3f659402fe7563abf99ad00de2209e6
545
+ Author: Scott Chacon <schacon@gee-mail.com>
546
+ Date: Sat Mar 15 10:31:28 2008 -0700
547
+
548
+ first commit
549
+
550
+ README | 6 ++++++
551
+ Rakefile | 23 +++++++++++++++++++++++
552
+ lib/simplegit.rb | 25 +++++++++++++++++++++++++
553
+ 3 files changed, 54 insertions(+)
554
+
555
+ As you can see, the `--stat` option prints below each commit entry a list of modified files, how many files were changed, and how many lines in those files were added and removed. It also puts a summary of the information at the end.
556
+ Another really useful option is `--pretty`. This option changes the log output to formats other than the default. A few prebuilt options are available for you to use. The `oneline` option prints each commit on a single line, which is useful if you’re looking at a lot of commits. In addition, the `short`, `full`, and `fuller` options show the output in roughly the same format but with less or more information, respectively:
557
+
558
+ $ git log --pretty=oneline
559
+ ca82a6dff817ec66f44342007202690a93763949 changed the version number
560
+ 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 removed unnecessary test code
561
+ a11bef06a3f659402fe7563abf99ad00de2209e6 first commit
562
+
563
+ The most interesting option is `format`, which allows you to specify your own log output format. This is especially useful when you’re generating output for machine parsing — because you specify the format explicitly, you know it won’t change with updates to Git:
564
+
565
+ $ git log --pretty=format:"%h - %an, %ar : %s"
566
+ ca82a6d - Scott Chacon, 11 months ago : changed the version number
567
+ 085bb3b - Scott Chacon, 11 months ago : removed unnecessary test code
568
+ a11bef0 - Scott Chacon, 11 months ago : first commit
569
+
570
+ Table 2-1 lists some of the more useful options that format takes.
571
+
572
+ <!-- Attention to translators: this is a table declaration.
573
+ The lines must be formatted as follows
574
+ <TAB><First column text><TAB><Second column text>
575
+ -->
576
+
577
+ Option Description of Output
578
+ %H Commit hash
579
+ %h Abbreviated commit hash
580
+ %T Tree hash
581
+ %t Abbreviated tree hash
582
+ %P Parent hashes
583
+ %p Abbreviated parent hashes
584
+ %an Author name
585
+ %ae Author e-mail
586
+ %ad Author date (format respects the --date= option)
587
+ %ar Author date, relative
588
+ %cn Committer name
589
+ %ce Committer email
590
+ %cd Committer date
591
+ %cr Committer date, relative
592
+ %s Subject
593
+
594
+ You may be wondering what the difference is between _author_ and _committer_. The _author_ is the person who originally wrote the patch, whereas the _committer_ is the person who last applied the patch. So, if you send in a patch to a project and one of the core members applies the patch, both of you get credit — you as the author and the core member as the committer. We’ll cover this distinction a bit more in *Chapter 5*.
595
+
596
+ The `oneline` and `format` options are particularly useful with another `log` option called `--graph`. This option adds a nice little ASCII graph showing your branch and merge history, which we can see in our copy of the Grit project repository:
597
+
598
+ $ git log --pretty=format:"%h %s" --graph
599
+ * 2d3acf9 ignore errors from SIGCHLD on trap
600
+ * 5e3ee11 Merge branch 'master' of git://github.com/dustin/grit
601
+ |\
602
+ | * 420eac9 Added a method for getting the current branch.
603
+ * | 30e367c timeout code and tests
604
+ * | 5a09431 add timeout protection to grit
605
+ * | e1193f8 support for heads with slashes in them
606
+ |/
607
+ * d6016bc require time for xmlschema
608
+ * 11d191e Merge branch 'defunkt' into local
609
+
610
+ Those are only some simple output-formatting options to `git log` — there are many more. Table 2-2 lists the options we’ve covered so far and some other common formatting options that may be useful, along with how they change the output of the `log` command.
611
+
612
+ <!-- Attention to translators: this is a table declaration.
613
+ The lines must be formatted as follows
614
+ <TAB><First column text><TAB><Second column text>
615
+ -->
616
+
617
+ Option Description
618
+ -p Show the patch introduced with each commit.
619
+ --word-diff Show the patch in a word diff format.
620
+ --stat Show statistics for files modified in each commit.
621
+ --shortstat Display only the changed/insertions/deletions line from the --stat command.
622
+ --name-only Show the list of files modified after the commit information.
623
+ --name-status Show the list of files affected with added/modified/deleted information as well.
624
+ --abbrev-commit Show only the first few characters of the SHA-1 checksum instead of all 40.
625
+ --relative-date Display the date in a relative format (for example, “2 weeks ago”) instead of using the full date format.
626
+ --graph Display an ASCII graph of the branch and merge history beside the log output.
627
+ --pretty Show commits in an alternate format. Options include oneline, short, full, fuller, and format (where you specify your own format).
628
+ --oneline A convenience option short for `--pretty=oneline --abbrev-commit`.
629
+
630
+ ### Limiting Log Output ###
631
+
632
+ In addition to output-formatting options, `git log` takes a number of useful limiting options — that is, options that let you show only a subset of commits. You’ve seen one such option already — the `-2` option, which shows only the last two commits. In fact, you can do `-<n>`, where `n` is any integer to show the last `n` commits. In reality, you’re unlikely to use that often, because Git by default pipes all output through a pager so you see only one page of log output at a time.
633
+
634
+ However, the time-limiting options such as `--since` and `--until` are very useful. For example, this command gets the list of commits made in the last two weeks:
635
+
636
+ $ git log --since=2.weeks
637
+
638
+ This command works with lots of formats — you can specify a specific date (“2008-01-15”) or a relative date such as “2 years 1 day 3 minutes ago”.
639
+
640
+ You can also filter the list to commits that match some search criteria. The `--author` option allows you to filter on a specific author, and the `--grep` option lets you search for keywords in the commit messages. (Note that if you specify both author and grep options, the command will match commits with both.)
641
+
642
+ If you want to specify multiple grep options, you have to add `--all-match` or the command will match commits with either.
643
+
644
+ The last really useful option to pass to `git log` as a filter is a path. If you specify a directory or file name, you can limit the log output to commits that introduced a change to those files. This is always the last option and is generally preceded by double dashes (`--`) to separate the paths from the options.
645
+
646
+ In Table 2-3 we’ll list these and a few other common options for your reference.
647
+
648
+ <!-- Attention to translators: this is a table declaration.
649
+ The lines must be formatted as follows
650
+ <TAB><First column text><TAB><Second column text>
651
+ -->
652
+
653
+ Option Description
654
+ -(n) Show only the last n commits
655
+ --since, --after Limit the commits to those whose CommitDate was made on-or-after the specified date/time.
656
+ --until, --before Limit the commits to those whose CommitDate was made on-or-before the specified date/time.
657
+ --author Only show commits in which the author entry matches the specified string.
658
+ --committer Only show commits in which the committer entry matches the specified string.
659
+
660
+
661
+ ### Limiting Log Output according to Date/Time ###
662
+
663
+ To determine which commits in the Git source code repository (git://git.kernel.org/pub/scm/git/git.git) have CommitDate on 2014-04-29 relative to your local timezone (as set on your computer), use
664
+
665
+ $ git log --after="2014-04-29 00:00:00" --before="2014-04-29 23:59:59" \
666
+ --pretty=fuller
667
+
668
+ As the output will be different according to the timezone where it will be run, it's recommended to always use an absolute time such as ISO 8601 format (which includes timezone information) as argument to `--after` and `--before`, so that everone running the command will get the same repeatable results.
669
+
670
+ To obtain commits made at a specific instant in time (e.g. 29 April 2013 at 17:07:22 CET), we can use
671
+
672
+ $ git log --after="2013-04-29T17:07:22+0200" \
673
+ --before="2013-04-29T17:07:22+0200" --pretty=fuller
674
+
675
+ commit de7c201a10857e5d424dbd8db880a6f24ba250f9
676
+ Author: Ramkumar Ramachandra <artagnon@gmail.com>
677
+ AuthorDate: Mon Apr 29 18:19:37 2013 +0530
678
+ Commit: Junio C Hamano <gitster@pobox.com>
679
+ CommitDate: Mon Apr 29 08:07:22 2013 -0700
680
+
681
+ git-completion.bash: lexical sorting for diff.statGraphWidth
682
+
683
+ df44483a (diff --stat: add config option to limit graph width,
684
+ 2012-03-01) added the option diff.startGraphWidth to the list of
685
+ configuration variables in git-completion.bash, but failed to notice
686
+ that the list is sorted alphabetically. Move it to its rightful place
687
+ in the list.
688
+
689
+ Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
690
+ Signed-off-by: Junio C Hamano <gitster@pobox.com>
691
+
692
+ The above times (`AuthorDate`, `CommitDate`) are displayed in default format (`--date=default`), which shows timezone information of respective author and commiter.
693
+
694
+ Other useful formats include `--date=iso` (ISO 8601), `--date=rfc` (RFC 2822), `--date=raw` (seconds since the epoch (1970-01-01 UTC)) `--date=local` (times according to your local timezone) as well as `--date=relative` (e.g. "2 hours ago").
695
+
696
+ When using `git log` without specifying time, the time defaults to the time at which the command is run on your computer (keeping the identical offset from UTC).
697
+
698
+ For example, running a `git log` at 09:00 on your computer with your timezone currently 3 hours ahead of UTC, makes the following two commands equivalent:
699
+
700
+ $ git log --after=2008-06-01 --before=2008-07-01
701
+ $ git log --after="2008-06-01T09:00:00+0300" \
702
+ --before="2008-07-01T09:00:00+0300"
703
+
704
+ As a final example, if you want to see which commits modifying test files in the Git source code history were committed by Junio Hamano with CommitDate being in the month of October 2008 (relative to the timezone of New York) and were not merges, you can run something like this:
705
+
706
+ $ git log --pretty="%h - %s" --author=gitster \
707
+ --after="2008-10-01T00:00:00-0400" \
708
+ --before="2008-10-31T23:59:59-0400" --no-merges -- t/
709
+ 5610e3b - Fix testcase failure when extended attribute
710
+ acd3b9e - Enhance hold_lock_file_for_{update,append}()
711
+ f563754 - demonstrate breakage of detached checkout wi
712
+ d1a43f2 - reset --hard/read-tree --reset -u: remove un
713
+ 51a94af - Fix "checkout --track -b newbranch" on detac
714
+ b0ad11e - pull: allow "git pull origin $something:$cur
715
+
716
+ Of the more than 36,000 commits in the Git source code history, this command shows the 6 that match those criteria.
717
+
718
+ ### Using a GUI to Visualize History ###
719
+
720
+ If you like to use a more graphical tool to visualize your commit history, you may want to take a look at a Tcl/Tk program called `gitk` that is distributed with Git. Gitk is basically a visual `git log` tool, and it accepts nearly all the filtering options that `git log` does. If you type `gitk` on the command line in your project, you should see something like Figure 2-2.
721
+
722
+ Insert 18333fig0202.png
723
+ Figure 2-2. The gitk history visualizer.
724
+
725
+ You can see the commit history in the top half of the window along with a nice ancestry graph. The diff viewer in the bottom half of the window shows you the changes introduced at any commit you click.
726
+
727
+ ## Undoing Things ##
728
+
729
+ At any stage, you may want to undo something. Here, we’ll review a few basic tools for undoing changes that you’ve made. Be careful, because you can’t always revert some of these undos. This is one of the few areas in Git where you may lose some work if you do it wrong.
730
+
731
+ ### Changing Your Last Commit ###
732
+
733
+ One of the common undos takes place when you commit too early and possibly forget to add some files, or you mess up your commit message. If you want to try that commit again, you can run commit with the `--amend` option:
734
+
735
+ $ git commit --amend
736
+
737
+ This command takes your staging area and uses it for the commit. If you’ve made no changes since your last commit (for instance, you run this command immediately after your previous commit), then your snapshot will look exactly the same and all you’ll change is your commit message.
738
+
739
+ The same commit-message editor fires up, but it already contains the message of your previous commit. You can edit the message the same as always, but it overwrites your previous commit.
740
+
741
+ As an example, if you commit and then realize you forgot to stage the changes in a file you wanted to add to this commit, you can do something like this:
742
+
743
+ $ git commit -m 'initial commit'
744
+ $ git add forgotten_file
745
+ $ git commit --amend
746
+
747
+ After these three commands, you end up with a single commit — the second commit replaces the results of the first.
748
+
749
+ ### Unstaging a Staged File ###
750
+
751
+ The next two sections demonstrate how to wrangle your staging area and working directory changes. The nice part is that the command you use to determine the state of those two areas also reminds you how to undo changes to them. For example, let’s say you’ve changed two files and want to commit them as two separate changes, but you accidentally type `git add *` and stage them both. How can you unstage one of the two? The `git status` command reminds you:
752
+
753
+ $ git add .
754
+ $ git status
755
+ On branch master
756
+ Changes to be committed:
757
+ (use "git reset HEAD <file>..." to unstage)
758
+
759
+ modified: README.txt
760
+ modified: benchmarks.rb
761
+
762
+
763
+ Right below the “Changes to be committed” text, it says "use `git reset HEAD <file>...` to unstage". So, let’s use that advice to unstage the `benchmarks.rb` file:
764
+
765
+ $ git reset HEAD benchmarks.rb
766
+ Unstaged changes after reset:
767
+ M benchmarks.rb
768
+ $ git status
769
+ On branch master
770
+ Changes to be committed:
771
+ (use "git reset HEAD <file>..." to unstage)
772
+
773
+ modified: README.txt
774
+
775
+ Changes not staged for commit:
776
+ (use "git add <file>..." to update what will be committed)
777
+ (use "git checkout -- <file>..." to discard changes in working directory)
778
+
779
+ modified: benchmarks.rb
780
+
781
+
782
+ The command is a bit strange, but it works. The `benchmarks.rb` file is modified but once again unstaged.
783
+
784
+ ### Unmodifying a Modified File ###
785
+
786
+ What if you realize that you don’t want to keep your changes to the `benchmarks.rb` file? How can you easily unmodify it — revert it back to what it looked like when you last committed (or initially cloned, or however you got it into your working directory)? Luckily, `git status` tells you how to do that, too. In the last example output, the unstaged area looks like this:
787
+
788
+ Changes not staged for commit:
789
+ (use "git add <file>..." to update what will be committed)
790
+ (use "git checkout -- <file>..." to discard changes in working directory)
791
+
792
+ modified: benchmarks.rb
793
+
794
+
795
+ It tells you pretty explicitly how to discard the changes you’ve made (at least, the newer versions of Git, 1.6.1 and later, do this — if you have an older version, we highly recommend upgrading it to get some of these nicer usability features). Let’s do what it says:
796
+
797
+ $ git checkout -- benchmarks.rb
798
+ $ git status
799
+ On branch master
800
+ Changes to be committed:
801
+ (use "git reset HEAD <file>..." to unstage)
802
+
803
+ modified: README.txt
804
+
805
+
806
+ You can see that the changes have been reverted. You should also realize that this is a dangerous command: any changes you made to that file are gone — you just copied another file over it. Don’t ever use this command unless you absolutely know that you don’t want the file. If you just need to get it out of the way, we’ll go over stashing and branching in the next chapter; these are generally better ways to go.
807
+
808
+ Remember, anything that is committed in Git can almost always be recovered. Even commits that were on branches that were deleted or commits that were overwritten with an `--amend` commit can be recovered (see *Chapter 9* for data recovery). However, anything you lose that was never committed is likely never to be seen again.
809
+
810
+ ## Working with Remotes ##
811
+
812
+ To be able to collaborate on any Git project, you need to know how to manage your remote repositories. Remote repositories are versions of your project that are hosted on the Internet or network somewhere. You can have several of them, each of which generally is either read-only or read/write for you. Collaborating with others involves managing these remote repositories and pushing and pulling data to and from them when you need to share work.
813
+ Managing remote repositories includes knowing how to add remote repositories, remove remotes that are no longer valid, manage various remote branches and define them as being tracked or not, and more. In this section, we’ll cover these remote-management skills.
814
+
815
+ ### Showing Your Remotes ###
816
+
817
+ To see which remote servers you have configured, you can run the `git remote` command. It lists the shortnames of each remote handle you’ve specified. If you’ve cloned your repository, you should at least see *origin* — that is the default name Git gives to the server you cloned from:
818
+
819
+ $ git clone git://github.com/schacon/ticgit.git
820
+ Cloning into 'ticgit'...
821
+ remote: Reusing existing pack: 1857, done.
822
+ remote: Total 1857 (delta 0), reused 0 (delta 0)
823
+ Receiving objects: 100% (1857/1857), 374.35 KiB | 193.00 KiB/s, done.
824
+ Resolving deltas: 100% (772/772), done.
825
+ Checking connectivity... done.
826
+ $ cd ticgit
827
+ $ git remote
828
+ origin
829
+
830
+ You can also specify `-v`, which shows you the URL that Git has stored for the shortname to be expanded to:
831
+
832
+ $ git remote -v
833
+ origin git://github.com/schacon/ticgit.git (fetch)
834
+ origin git://github.com/schacon/ticgit.git (push)
835
+
836
+ If you have more than one remote, the command lists them all. For example, my Grit repository looks something like this.
837
+
838
+ $ cd grit
839
+ $ git remote -v
840
+ bakkdoor git://github.com/bakkdoor/grit.git
841
+ cho45 git://github.com/cho45/grit.git
842
+ defunkt git://github.com/defunkt/grit.git
843
+ koke git://github.com/koke/grit.git
844
+ origin git@github.com:mojombo/grit.git
845
+
846
+ This means I can pull contributions from any of these users pretty easily. But notice that only the origin remote is an SSH URL, so it’s the only one I can push to (we’ll cover why this is in *Chapter 4*).
847
+
848
+ ### Adding Remote Repositories ###
849
+
850
+ I’ve mentioned and given some demonstrations of adding remote repositories in previous sections, but here is how to do it explicitly. To add a new remote Git repository as a shortname you can reference easily, run `git remote add [shortname] [url]`:
851
+
852
+ $ git remote
853
+ origin
854
+ $ git remote add pb git://github.com/paulboone/ticgit.git
855
+ $ git remote -v
856
+ origin git://github.com/schacon/ticgit.git
857
+ pb git://github.com/paulboone/ticgit.git
858
+
859
+ Now you can use the string `pb` on the command line in lieu of the whole URL. For example, if you want to fetch all the information that Paul has but that you don’t yet have in your repository, you can run `git fetch pb`:
860
+
861
+ $ git fetch pb
862
+ remote: Counting objects: 58, done.
863
+ remote: Compressing objects: 100% (41/41), done.
864
+ remote: Total 44 (delta 24), reused 1 (delta 0)
865
+ Unpacking objects: 100% (44/44), done.
866
+ From git://github.com/paulboone/ticgit
867
+ * [new branch] master -> pb/master
868
+ * [new branch] ticgit -> pb/ticgit
869
+
870
+ Paul’s master branch is accessible locally as `pb/master` — you can merge it into one of your branches, or you can check out a local branch at that point if you want to inspect it.
871
+
872
+ ### Fetching and Pulling from Your Remotes ###
873
+
874
+ As you just saw, to get data from your remote projects, you can run:
875
+
876
+ $ git fetch [remote-name]
877
+
878
+ The command goes out to that remote project and pulls down all the data from that remote project that you don’t have yet. After you do this, you should have references to all the branches from that remote, which you can merge in or inspect at any time. (We’ll go over what branches are and how to use them in much more detail in *Chapter 3*.)
879
+
880
+ If you clone a repository, the command automatically adds that remote repository under the name *origin*. So, `git fetch origin` fetches any new work that has been pushed to that server since you cloned (or last fetched from) it. It’s important to note that the `fetch` command pulls the data to your local repository — it doesn’t automatically merge it with any of your work or modify what you’re currently working on. You have to merge it manually into your work when you’re ready.
881
+
882
+ If you have a branch set up to track a remote branch (see the next section and *Chapter 3* for more information), you can use the `git pull` command to automatically fetch and then merge a remote branch into your current branch. This may be an easier or more comfortable workflow for you; and by default, the `git clone` command automatically sets up your local master branch to track the remote master branch on the server you cloned from (assuming the remote has a master branch). Running `git pull` generally fetches data from the server you originally cloned from and automatically tries to merge it into the code you’re currently working on.
883
+
884
+ ### Pushing to Your Remotes ###
885
+
886
+ When you have your project at a point that you want to share, you have to push it upstream. The command for this is simple: `git push [remote-name] [branch-name]`. If you want to push your master branch to your `origin` server (again, cloning generally sets up both of those names for you automatically), then you can run this to push your work back up to the server:
887
+
888
+ $ git push origin master
889
+
890
+ This command works only if you cloned from a server to which you have write access and if nobody has pushed in the meantime. If you and someone else clone at the same time and they push upstream and then you push upstream, your push will rightly be rejected. You’ll have to pull down their work first and incorporate it into yours before you’ll be allowed to push. See *Chapter 3* for more detailed information on how to push to remote servers.
891
+
892
+ ### Inspecting a Remote ###
893
+
894
+ If you want to see more information about a particular remote, you can use the `git remote show [remote-name]` command. If you run this command with a particular shortname, such as `origin`, you get something like this:
895
+
896
+ $ git remote show origin
897
+ * remote origin
898
+ URL: git://github.com/schacon/ticgit.git
899
+ Remote branch merged with 'git pull' while on branch master
900
+ master
901
+ Tracked remote branches
902
+ master
903
+ ticgit
904
+
905
+ It lists the URL for the remote repository as well as the tracking branch information. The command helpfully tells you that if you’re on the master branch and you run `git pull`, it will automatically merge in the master branch on the remote after it fetches all the remote references. It also lists all the remote references it has pulled down.
906
+
907
+ That is a simple example you’re likely to encounter. When you’re using Git more heavily, however, you may see much more information from `git remote show`:
908
+
909
+ $ git remote show origin
910
+ * remote origin
911
+ URL: git@github.com:defunkt/github.git
912
+ Remote branch merged with 'git pull' while on branch issues
913
+ issues
914
+ Remote branch merged with 'git pull' while on branch master
915
+ master
916
+ New remote branches (next fetch will store in remotes/origin)
917
+ caching
918
+ Stale tracking branches (use 'git remote prune')
919
+ libwalker
920
+ walker2
921
+ Tracked remote branches
922
+ acl
923
+ apiv2
924
+ dashboard2
925
+ issues
926
+ master
927
+ postgres
928
+ Local branch pushed with 'git push'
929
+ master:master
930
+
931
+ This command shows which branch is automatically pushed when you run `git push` on certain branches. It also shows you which remote branches on the server you don’t yet have, which remote branches you have that have been removed from the server, and multiple branches that are automatically merged when you run `git pull`.
932
+
933
+ ### Removing and Renaming Remotes ###
934
+
935
+ If you want to rename a reference, in newer versions of Git you can run `git remote rename` to change a remote’s shortname. For instance, if you want to rename `pb` to `paul`, you can do so with `git remote rename`:
936
+
937
+ $ git remote rename pb paul
938
+ $ git remote
939
+ origin
940
+ paul
941
+
942
+ It’s worth mentioning that this changes your remote branch names, too. What used to be referenced at `pb/master` is now at `paul/master`.
943
+
944
+ If you want to remove a reference for some reason — you’ve moved the server or are no longer using a particular mirror, or perhaps a contributor isn’t contributing anymore — you can use `git remote rm`:
945
+
946
+ $ git remote rm paul
947
+ $ git remote
948
+ origin
949
+
950
+ ## Tagging ##
951
+
952
+ Like most VCSs, Git has the ability to tag specific points in history as being important. Generally, people use this functionality to mark release points (`v1.0`, and so on). In this section, you’ll learn how to list the available tags, how to create new tags, and what the different types of tags are.
953
+
954
+ ### Listing Your Tags ###
955
+
956
+ Listing the available tags in Git is straightforward. Just type `git tag`:
957
+
958
+ $ git tag
959
+ v0.1
960
+ v1.3
961
+
962
+ This command lists the tags in alphabetical order; the order in which they appear has no real importance.
963
+
964
+ You can also search for tags with a particular pattern. The Git source repo, for instance, contains more than 240 tags. If you’re only interested in looking at the 1.4.2 series, you can run this:
965
+
966
+ $ git tag -l 'v1.4.2.*'
967
+ v1.4.2.1
968
+ v1.4.2.2
969
+ v1.4.2.3
970
+ v1.4.2.4
971
+
972
+ ### Creating Tags ###
973
+
974
+ Git uses two main types of tags: lightweight and annotated. A lightweight tag is very much like a branch that doesn’t change — it’s just a pointer to a specific commit. Annotated tags, however, are stored as full objects in the Git database. They’re checksummed; contain the tagger name, e-mail, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG). It’s generally recommended that you create annotated tags so you can have all this information; but if you want a temporary tag or for some reason don’t want to keep the other information, lightweight tags are available too.
975
+
976
+ ### Annotated Tags ###
977
+
978
+ Creating an annotated tag in Git is simple. The easiest way is to specify `-a` when you run the `tag` command:
979
+
980
+ $ git tag -a v1.4 -m 'my version 1.4'
981
+ $ git tag
982
+ v0.1
983
+ v1.3
984
+ v1.4
985
+
986
+ The `-m` specifies a tagging message, which is stored with the tag. If you don’t specify a message for an annotated tag, Git launches your editor so you can type it in.
987
+
988
+ You can see the tag data along with the commit that was tagged by using the `git show` command:
989
+
990
+ $ git show v1.4
991
+ tag v1.4
992
+ Tagger: Scott Chacon <schacon@gee-mail.com>
993
+ Date: Mon Feb 9 14:45:11 2009 -0800
994
+
995
+ my version 1.4
996
+
997
+ commit 15027957951b64cf874c3557a0f3547bd83b3ff6
998
+ Merge: 4a447f7... a6b4c97...
999
+ Author: Scott Chacon <schacon@gee-mail.com>
1000
+ Date: Sun Feb 8 19:02:46 2009 -0800
1001
+
1002
+ Merge branch 'experiment'
1003
+
1004
+ That shows the tagger information, the date the commit was tagged, and the annotation message before showing the commit information.
1005
+
1006
+ ### Signed Tags ###
1007
+
1008
+ You can also sign your tags with GPG, assuming you have a private key. All you have to do is use `-s` instead of `-a`:
1009
+
1010
+ $ git tag -s v1.5 -m 'my signed 1.5 tag'
1011
+ You need a passphrase to unlock the secret key for
1012
+ user: "Scott Chacon <schacon@gee-mail.com>"
1013
+ 1024-bit DSA key, ID F721C45A, created 2009-02-09
1014
+
1015
+ If you run `git show` on that tag, you can see your GPG signature attached to it:
1016
+
1017
+ $ git show v1.5
1018
+ tag v1.5
1019
+ Tagger: Scott Chacon <schacon@gee-mail.com>
1020
+ Date: Mon Feb 9 15:22:20 2009 -0800
1021
+
1022
+ my signed 1.5 tag
1023
+ -----BEGIN PGP SIGNATURE-----
1024
+ Version: GnuPG v1.4.8 (Darwin)
1025
+
1026
+ iEYEABECAAYFAkmQurIACgkQON3DxfchxFr5cACeIMN+ZxLKggJQf0QYiQBwgySN
1027
+ Ki0An2JeAVUCAiJ7Ox6ZEtK+NvZAj82/
1028
+ =WryJ
1029
+ -----END PGP SIGNATURE-----
1030
+ commit 15027957951b64cf874c3557a0f3547bd83b3ff6
1031
+ Merge: 4a447f7... a6b4c97...
1032
+ Author: Scott Chacon <schacon@gee-mail.com>
1033
+ Date: Sun Feb 8 19:02:46 2009 -0800
1034
+
1035
+ Merge branch 'experiment'
1036
+
1037
+ A bit later, you’ll learn how to verify signed tags.
1038
+
1039
+ ### Lightweight Tags ###
1040
+
1041
+ Another way to tag commits is with a lightweight tag. This is basically the commit checksum stored in a file — no other information is kept. To create a lightweight tag, don’t supply the `-a`, `-s`, or `-m` option:
1042
+
1043
+ $ git tag v1.4-lw
1044
+ $ git tag
1045
+ v0.1
1046
+ v1.3
1047
+ v1.4
1048
+ v1.4-lw
1049
+ v1.5
1050
+
1051
+ This time, if you run `git show` on the tag, you don’t see the extra tag information. The command just shows the commit:
1052
+
1053
+ $ git show v1.4-lw
1054
+ commit 15027957951b64cf874c3557a0f3547bd83b3ff6
1055
+ Merge: 4a447f7... a6b4c97...
1056
+ Author: Scott Chacon <schacon@gee-mail.com>
1057
+ Date: Sun Feb 8 19:02:46 2009 -0800
1058
+
1059
+ Merge branch 'experiment'
1060
+
1061
+ ### Verifying Tags ###
1062
+
1063
+ To verify a signed tag, you use `git tag -v [tag-name]`. This command uses GPG to verify the signature. You need the signer’s public key in your keyring for this to work properly:
1064
+
1065
+ $ git tag -v v1.4.2.1
1066
+ object 883653babd8ee7ea23e6a5c392bb739348b1eb61
1067
+ type commit
1068
+ tag v1.4.2.1
1069
+ tagger Junio C Hamano <junkio@cox.net> 1158138501 -0700
1070
+
1071
+ GIT 1.4.2.1
1072
+
1073
+ Minor fixes since 1.4.2, including git-mv and git-http with alternates.
1074
+ gpg: Signature made Wed Sep 13 02:08:25 2006 PDT using DSA key ID F3119B9A
1075
+ gpg: Good signature from "Junio C Hamano <junkio@cox.net>"
1076
+ gpg: aka "[jpeg image of size 1513]"
1077
+ Primary key fingerprint: 3565 2A26 2040 E066 C9A7 4A7D C0C6 D9A4 F311 9B9A
1078
+
1079
+ If you don’t have the signer’s public key, you get something like this instead:
1080
+
1081
+ gpg: Signature made Wed Sep 13 02:08:25 2006 PDT using DSA key ID F3119B9A
1082
+ gpg: Can't check signature: public key not found
1083
+ error: could not verify the tag 'v1.4.2.1'
1084
+
1085
+ ### Tagging Later ###
1086
+
1087
+ You can also tag commits after you’ve moved past them. Suppose your commit history looks like this:
1088
+
1089
+ $ git log --pretty=oneline
1090
+ 15027957951b64cf874c3557a0f3547bd83b3ff6 Merge branch 'experiment'
1091
+ a6b4c97498bd301d84096da251c98a07c7723e65 beginning write support
1092
+ 0d52aaab4479697da7686c15f77a3d64d9165190 one more thing
1093
+ 6d52a271eda8725415634dd79daabbc4d9b6008e Merge branch 'experiment'
1094
+ 0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc added a commit function
1095
+ 4682c3261057305bdd616e23b64b0857d832627b added a todo file
1096
+ 166ae0c4d3f420721acbb115cc33848dfcc2121a started write support
1097
+ 9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
1098
+ 964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo
1099
+ 8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
1100
+
1101
+ Now, suppose you forgot to tag the project at `v1.2`, which was at the "updated rakefile" commit. You can add it after the fact. To tag that commit, you specify the commit checksum (or part of it) at the end of the command:
1102
+
1103
+ $ git tag -a v1.2 -m 'version 1.2' 9fceb02
1104
+
1105
+ You can see that you’ve tagged the commit:
1106
+
1107
+ $ git tag
1108
+ v0.1
1109
+ v1.2
1110
+ v1.3
1111
+ v1.4
1112
+ v1.4-lw
1113
+ v1.5
1114
+
1115
+ $ git show v1.2
1116
+ tag v1.2
1117
+ Tagger: Scott Chacon <schacon@gee-mail.com>
1118
+ Date: Mon Feb 9 15:32:16 2009 -0800
1119
+
1120
+ version 1.2
1121
+ commit 9fceb02d0ae598e95dc970b74767f19372d61af8
1122
+ Author: Magnus Chacon <mchacon@gee-mail.com>
1123
+ Date: Sun Apr 27 20:43:35 2008 -0700
1124
+
1125
+ updated rakefile
1126
+ ...
1127
+
1128
+ ### Sharing Tags ###
1129
+
1130
+ By default, the `git push` command doesn’t transfer tags to remote servers. You will have to explicitly push tags to a shared server after you have created them. This process is just like sharing remote branches — you can run `git push origin [tagname]`.
1131
+
1132
+ $ git push origin v1.5
1133
+ Counting objects: 50, done.
1134
+ Compressing objects: 100% (38/38), done.
1135
+ Writing objects: 100% (44/44), 4.56 KiB, done.
1136
+ Total 44 (delta 18), reused 8 (delta 1)
1137
+ To git@github.com:schacon/simplegit.git
1138
+ * [new tag] v1.5 -> v1.5
1139
+
1140
+ If you have a lot of tags that you want to push up at once, you can also use the `--tags` option to the `git push` command. This will transfer all of your tags to the remote server that are not already there.
1141
+
1142
+ $ git push origin --tags
1143
+ Counting objects: 50, done.
1144
+ Compressing objects: 100% (38/38), done.
1145
+ Writing objects: 100% (44/44), 4.56 KiB, done.
1146
+ Total 44 (delta 18), reused 8 (delta 1)
1147
+ To git@github.com:schacon/simplegit.git
1148
+ * [new tag] v0.1 -> v0.1
1149
+ * [new tag] v1.2 -> v1.2
1150
+ * [new tag] v1.4 -> v1.4
1151
+ * [new tag] v1.4-lw -> v1.4-lw
1152
+ * [new tag] v1.5 -> v1.5
1153
+
1154
+ Now, when someone else clones or pulls from your repository, they will get all your tags as well.
1155
+
1156
+ ## Tips and Tricks ##
1157
+
1158
+ Before we finish this chapter on basic Git, a few little tips and tricks may make your Git experience a bit simpler, easier, or more familiar. Many people use Git without using any of these tips, and we won’t refer to them or assume you’ve used them later in the book; but you should probably know how to do them.
1159
+
1160
+ ### Auto-Completion ###
1161
+
1162
+ If you use the Bash shell, Git comes with a nice auto-completion script you can enable. Download it directly from the Git source code at https://github.com/git/git/blob/master/contrib/completion/git-completion.bash . Copy this file to your home directory, and add this to your `.bashrc` file:
1163
+
1164
+ source ~/git-completion.bash
1165
+
1166
+ If you want to set up Git to automatically have Bash shell completion for all users, copy this script to the `/opt/local/etc/bash_completion.d` directory on Mac systems or to the `/etc/bash_completion.d/` directory on Linux systems. This is a directory of scripts that Bash will automatically load to provide shell completions.
1167
+
1168
+ If you’re using Windows with Git Bash, which is the default when installing Git on Windows with msysGit, auto-completion should be preconfigured.
1169
+
1170
+ Press the Tab key when you’re writing a Git command, and it should return a set of suggestions for you to pick from:
1171
+
1172
+ $ git co<tab><tab>
1173
+ commit config
1174
+
1175
+ In this case, typing `git co` and then pressing the Tab key twice suggests commit and config. Adding `m<tab>` completes `git commit` automatically.
1176
+
1177
+ This also works with options, which is probably more useful. For instance, if you’re running a `git log` command and can’t remember one of the options, you can start typing it and press Tab to see what matches:
1178
+
1179
+ $ git log --s<tab>
1180
+ --shortstat --since= --src-prefix= --stat --summary
1181
+
1182
+ That’s a pretty nice trick and may save you some time and documentation reading.
1183
+
1184
+ ### Git Aliases ###
1185
+
1186
+ Git doesn’t infer your command if you type it in partially. If you don’t want to type the entire text of each of the Git commands, you can easily set up an alias for each command using `git config`. Here are a couple of examples you may want to set up:
1187
+
1188
+ $ git config --global alias.co checkout
1189
+ $ git config --global alias.br branch
1190
+ $ git config --global alias.ci commit
1191
+ $ git config --global alias.st status
1192
+
1193
+ This means that, for example, instead of typing `git commit`, you just need to type `git ci`. As you go on using Git, you’ll probably use other commands frequently as well; in this case, don’t hesitate to create new aliases.
1194
+
1195
+ This technique can also be very useful in creating commands that you think should exist. For example, to correct the usability problem you encountered with unstaging a file, you can add your own unstage alias to Git:
1196
+
1197
+ $ git config --global alias.unstage 'reset HEAD --'
1198
+
1199
+ This makes the following two commands equivalent:
1200
+
1201
+ $ git unstage fileA
1202
+ $ git reset HEAD fileA
1203
+
1204
+ This seems a bit clearer. It’s also common to add a `last` command, like this:
1205
+
1206
+ $ git config --global alias.last 'log -1 HEAD'
1207
+
1208
+ This way, you can see the last commit easily:
1209
+
1210
+ $ git last
1211
+ commit 66938dae3329c7aebe598c2246a8e6af90d04646
1212
+ Author: Josh Goebel <dreamer3@example.com>
1213
+ Date: Tue Aug 26 19:48:51 2008 +0800
1214
+
1215
+ test for current head
1216
+
1217
+ Signed-off-by: Scott Chacon <schacon@example.com>
1218
+
1219
+ As you can tell, Git simply replaces the new command with whatever you alias it to. However, maybe you want to run an external command, rather than a Git subcommand. In that case, you start the command with a `!` character. This is useful if you write your own tools that work with a Git repository. We can demonstrate by aliasing `git visual` to run `gitk`:
1220
+
1221
+ $ git config --global alias.visual '!gitk'
1222
+
1223
+ ## Summary ##
1224
+
1225
+ At this point, you can do all the basic local Git operations — creating or cloning a repository, making changes, staging and committing those changes, and viewing the history of all the changes the repository has been through. Next, we’ll cover Git’s killer feature: its branching model.