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,28 @@
1
+ ul {
2
+ margin: 20px;
3
+ }
4
+
5
+ ol {
6
+ margin: 20px;
7
+ }
8
+
9
+ body pre {
10
+ margin: 10px;
11
+ font-weight: bold;
12
+ }
13
+
14
+ body pre2 {
15
+ background-color: silver;
16
+ padding: 10px;
17
+ border-top-style: solid;
18
+ border-left-style: solid;
19
+ border-left-width: 1px;
20
+ border-top-width: 1px;
21
+ overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
22
+ white-space: pre-wrap; /* css-3 */
23
+ white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
24
+ white-space: -pre-wrap; /* Opera 4-6 */
25
+ white-space: -o-pre-wrap; /* Opera 7 */
26
+ /* width: 99%; */
27
+ word-wrap: break-word; /* Internet Explorer 5.5+ */
28
+ }
Binary file
@@ -0,0 +1,257 @@
1
+ # Iniciando #
2
+
3
+ Este capítulo tratará sobre iniciarnos en el uso de Git. Iniciaremos explicando algunos conceptos sobre herramientas de control de versiones, luego veremos cómo ejecutar Git en nuestro sistema y finalmente cónmo configurarlo para iniciar a trabajar con el. Al final de este capítulo podremos entender por qué existe Git, por que deberíamos usarlo y deberíamos ser capaces de configurarlo para trabajar con el.
4
+
5
+ ## Acerca del Control de Versiones ##
6
+
7
+ ¿Qué es control de versiones, y por qué debería importarte? El control de versiones es un sistema que registra los cambios realizado a un archivo o conjunto de archivos a través del tiempo, de manera que puedas llamar una versión específica tiempo después. Para los ejemplos en este libro utilizaremos el código fuente del software como los archivos a ser controlados por versiones, aunque en realidad puedes hacer esto con casi cualquier tipo de archivo en una computadora.
8
+
9
+ Si eres diseñador gráfico o diseñador web y quieres mantener cada versión de una imagen o de un diseño (que seguramente lo querrás hacer), usar un Sistema de Control de Versiones (VCS por su siglas en inglés) es una sabia decisión. Te permite revertir archivos a un estado previo, revertir el proyecto completo a un estado anterior, comparar cambios en el tiempo, ver quien modificó algo por última vez que pudo estar causando un problema, quien introdujo un problema y cuando, y más. Usar un VCS también significa que si dañas algo o pierdes archivos, generalmente podrás recuperarlos con facilidad. Adicionalmente, obtienes todo esto por muy poco trabajo extra.
10
+
11
+ ### Local Version Control Systems ###
12
+
13
+ Many people’s version-control method of choice is to copy files into another directory (perhaps a time-stamped directory, if they’re clever). This approach is very common because it is so simple, but it is also incredibly error prone. It is easy to forget which directory you’re in and accidentally write to the wrong file or copy over files you don’t mean to.
14
+
15
+ To deal with this issue, programmers long ago developed local VCSs that had a simple database that kept all the changes to files under revision control (see Figure 1-1).
16
+
17
+ Insert 18333fig0101.png
18
+ Figure 1-1. Local version control diagram
19
+
20
+ One of the more popular VCS tools was a system called rcs, which is still distributed with many computers today. Even the popular Mac OS X operating system includes the rcs command when you install the Developer Tools. This tool basically works by keeping patch sets (that is, the differences between files) from one change to another in a special format on disk; it can then re-create what any file looked like at any point in time by adding up all the patches.
21
+
22
+ ### Centralized Version Control Systems ###
23
+
24
+ The next major issue that people encounter is that they need to collaborate with developers on other systems. To deal with this problem, Centralized Version Control Systems (CVCSs) were developed. These systems, such as CVS, Subversion, and Perforce, have a single server that contains all the versioned files, and a number of clients that check out files from that central place. For many years, this has been the standard for version control (see Figure 1-2).
25
+
26
+ Insert 18333fig0102.png
27
+ Figure 1-2. Centralized version control diagram
28
+
29
+ This setup offers many advantages, especially over local VCSs. For example, everyone knows to a certain degree what everyone else on the project is doing. Administrators have fine-grained control over who can do what; and it’s far easier to administer a CVCS than it is to deal with local databases on every client.
30
+
31
+ However, this setup also has some serious downsides. The most obvious is the single point of failure that the centralized server represents. If that server goes down for an hour, then during that hour nobody can collaborate at all or save versioned changes to anything they’re working on. If the hard disk the central database is on becomes corrupted, and proper backups haven’t been kept, you lose absolutely everything—the entire history of the project except whatever single snapshots people happen to have on their local machines. Local VCS systems suffer from this same problem—whenever you have the entire history of the project in a single place, you risk losing everything.
32
+
33
+ ### Distributed Version Control Systems ###
34
+
35
+ This is where Distributed Version Control Systems (DVCSs) step in. In a DVCS (such as Git, Mercurial, Bazaar or Darcs), clients don’t just check out the latest snapshot of the files: they fully mirror the repository. Thus if any server dies, and these systems were collaborating via it, any of the client repositories can be copied back up to the server to restore it. Every checkout is really a full backup of all the data (see Figure 1-3).
36
+
37
+ Insert 18333fig0103.png
38
+ Figure 1-3. Distributed version control diagram
39
+
40
+ Furthermore, many of these systems deal pretty well with having several remote repositories they can work with, so you can collaborate with different groups of people in different ways simultaneously within the same project. This allows you to set up several types of workflows that aren’t possible in centralized systems, such as hierarchical models.
41
+
42
+ ## A Short History of Git ##
43
+
44
+ As with many great things in life, Git began with a bit of creative destruction and fiery controversy. The Linux kernel is an open source software project of fairly large scope. For most of the lifetime of the Linux kernel maintenance (1991–2002), changes to the software were passed around as patches and archived files. In 2002, the Linux kernel project began using a proprietary DVCS system called BitKeeper.
45
+
46
+ In 2005, the relationship between the community that developed the Linux kernel and the commercial company that developed BitKeeper broke down, and the tool’s free-of-charge status was revoked. This prompted the Linux development community (and in particular Linus Torvalds, the creator of Linux) to develop their own tool based on some of the lessons they learned while using BitKeeper. Some of the goals of the new system were as follows:
47
+
48
+ * Speed
49
+ * Simple design
50
+ * Strong support for non-linear development (thousands of parallel branches)
51
+ * Fully distributed
52
+ * Able to handle large projects like the Linux kernel efficiently (speed and data size)
53
+
54
+ Since its birth in 2005, Git has evolved and matured to be easy to use and yet retain these initial qualities. It’s incredibly fast, it’s very efficient with large projects, and it has an incredible branching system for non-linear development (See Chapter 3).
55
+
56
+ ## Git Basics ##
57
+
58
+ So, what is Git in a nutshell? This is an important section to absorb, because if you understand what Git is and the fundamentals of how it works, then using Git effectively will probably be much easier for you. As you learn Git, try to clear your mind of the things you may know about other VCSs, such as Subversion and Perforce; doing so will help you avoid subtle confusion when using the tool. Git stores and thinks about information much differently than these other systems, even though the user interface is fairly similar; understanding those differences will help prevent you from becoming confused while using it.
59
+
60
+ ### Snapshots, Not Differences ###
61
+
62
+ The major difference between Git and any other VCS (Subversion and friends included) is the way Git thinks about its data. Conceptually, most other systems store information as a list of file-based changes. These systems (CVS, Subversion, Perforce, Bazaar, and so on) think of the information they keep as a set of files and the changes made to each file over time, as illustrated in Figure 1-4.
63
+
64
+ Insert 18333fig0104.png
65
+ Figure 1-4. Other systems tend to store data as changes to a base version of each file.
66
+
67
+ Git doesn’t think of or store its data this way. Instead, Git thinks of its data more like a set of snapshots of a mini filesystem. Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. To be efficient, if files have not changed, Git doesn’t store the file again—just a link to the previous identical file it has already stored. Git thinks about its data more like Figure 1-5.
68
+
69
+ Insert 18333fig0105.png
70
+ Figure 1-5. Git stores data as snapshots of the project over time.
71
+
72
+ This is an important distinction between Git and nearly all other VCSs. It makes Git reconsider almost every aspect of version control that most other systems copied from the previous generation. This makes Git more like a mini filesystem with some incredibly powerful tools built on top of it, rather than simply a VCS. We’ll explore some of the benefits you gain by thinking of your data this way when we cover Git branching in Chapter 3.
73
+
74
+ ### Nearly Every Operation Is Local ###
75
+
76
+ Most operations in Git only need local files and resources to operate – generally no information is needed from another computer on your network. If you’re used to a CVCS where most operations have that network latency overhead, this aspect of Git will make you think that the gods of speed have blessed Git with unworldly powers. Because you have the entire history of the project right there on your local disk, most operations seem almost instantaneous.
77
+
78
+ For example, to browse the history of the project, Git doesn’t need to go out to the server to get the history and display it for you—it simply reads it directly from your local database. This means you see the project history almost instantly. If you want to see the changes introduced between the current version of a file and the file a month ago, Git can look up the file a month ago and do a local difference calculation, instead of having to either ask a remote server to do it or pull an older version of the file from the remote server to do it locally.
79
+
80
+ This also means that there is very little you can’t do if you’re offline or off VPN. If you get on an airplane or a train and want to do a little work, you can commit happily until you get to a network connection to upload. If you go home and can’t get your VPN client working properly, you can still work. In many other systems, doing so is either impossible or painful. In Perforce, for example, you can’t do much when you aren’t connected to the server; and in Subversion and CVS, you can edit files, but you can’t commit changes to your database (because your database is offline). This may not seem like a huge deal, but you may be surprised what a big difference it can make.
81
+
82
+ ### Git Has Integrity ###
83
+
84
+ Everything in Git is check-summed before it is stored and is then referred to by that checksum. This means it’s impossible to change the contents of any file or directory without Git knowing about it. This functionality is built into Git at the lowest levels and is integral to its philosophy. You can’t lose information in transit or get file corruption without Git being able to detect it.
85
+
86
+ The mechanism that Git uses for this checksumming is called a SHA-1 hash. This is a 40-character string composed of hexadecimal characters (0–9 and a–f) and calculated based on the contents of a file or directory structure in Git. A SHA-1 hash looks something like this:
87
+
88
+ 24b9da6552252987aa493b52f8696cd6d3b00373
89
+
90
+ You will see these hash values all over the place in Git because it uses them so much. In fact, Git stores everything not by file name but in the Git database addressable by the hash value of its contents.
91
+
92
+ ### Git Generally Only Adds Data ###
93
+
94
+ When you do actions in Git, nearly all of them only add data to the Git database. It is very difficult to get the system to do anything that is not undoable or to make it erase data in any way. As in any VCS, you can lose or mess up changes you haven’t committed yet; but after you commit a snapshot into Git, it is very difficult to lose, especially if you regularly push your database to another repository.
95
+
96
+ This makes using Git a joy because we know we can experiment without the danger of severely screwing things up. For a more in-depth look at how Git stores its data and how you can recover data that seems lost, see “Under the Covers” in Chapter 9.
97
+
98
+ ### The Three States ###
99
+
100
+ Now, pay attention. This is the main thing to remember about Git if you want the rest of your learning process to go smoothly. Git has three main states that your files can reside in: committed, modified, and staged. Committed means that the data is safely stored in your local database. Modified means that you have changed the file but have not committed it to your database yet. Staged means that you have marked a modified file in its current version to go into your next commit snapshot.
101
+
102
+ This leads us to the three main sections of a Git project: the Git directory, the working directory, and the staging area.
103
+
104
+ Insert 18333fig0106.png
105
+ Figure 1-6. Working directory, staging area, and git directory
106
+
107
+ The Git directory is where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone a repository from another computer.
108
+
109
+ The working directory is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify.
110
+
111
+ The staging area is a simple file, generally contained in your Git directory, that stores information about what will go into your next commit. It’s sometimes referred to as the index, but it’s becoming standard to refer to it as the staging area.
112
+
113
+ The basic Git workflow goes something like this:
114
+
115
+ 1. You modify files in your working directory.
116
+ 2. You stage the files, adding snapshots of them to your staging area.
117
+ 3. You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.
118
+
119
+ If a particular version of a file is in the git directory, it’s considered committed. If it’s modified but has been added to the staging area, it is staged. And if it was changed since it was checked out but has not been staged, it is modified. In Chapter 2, you’ll learn more about these states and how you can either take advantage of them or skip the staged part entirely.
120
+
121
+ ## Installing Git ##
122
+
123
+ Let’s get into using some Git. First things first—you have to install it. You can get it a number of ways; the two major ones are to install it from source or to install an existing package for your platform.
124
+
125
+ ### Installing from Source ###
126
+
127
+ If you can, it’s generally useful to install Git from source, because you’ll get the most recent version. Each version of Git tends to include useful UI enhancements, so getting the latest version is often the best route if you feel comfortable compiling software from source. It is also the case that many Linux distributions contain very old packages; so unless you’re on a very up-to-date distro or are using backports, installing from source may be the best bet.
128
+
129
+ To install Git, you need to have the following libraries that Git depends on: curl, zlib, openssl, expat, and libiconv. For example, if you’re on a system that has yum (such as Fedora) or apt-get (such as a Debian based system), you can use one of these commands to install all of the dependencies:
130
+
131
+ $ yum install curl-devel expat-devel gettext-devel \
132
+ openssl-devel zlib-devel
133
+
134
+ $ apt-get install curl-devel expat-devel gettext-devel \
135
+ openssl-devel zlib-devel
136
+
137
+ When you have all the necessary dependencies, you can go ahead and grab the latest snapshot from the Git web site:
138
+
139
+ http://git-scm.com/download
140
+
141
+ Then, compile and install:
142
+
143
+ $ tar -zxf git-1.6.0.5.tar.gz
144
+ $ cd git-1.6.0.5
145
+ $ make prefix=/usr/local all
146
+ $ sudo make prefix=/usr/local install
147
+
148
+ After this is done, you can also get Git via Git itself for updates:
149
+
150
+ $ git clone git://git.kernel.org/pub/scm/git/git.git
151
+
152
+ ### Installing on Linux ###
153
+
154
+ If you want to install Git on Linux via a binary installer, you can generally do so through the basic package-management tool that comes with your distribution. If you’re on Fedora, you can use yum:
155
+
156
+ $ yum install git-core
157
+
158
+ Or if you’re on a Debian-based distribution like Ubuntu, try apt-get:
159
+
160
+ $ apt-get install git
161
+
162
+ ### Installing on Mac ###
163
+
164
+ There are two easy ways to install Git on a Mac. The easiest is to use the graphical Git installer, which you can download from the SourceForge page (see Figure 1-7):
165
+
166
+ http://sourceforge.net/projects/git-osx-installer/
167
+
168
+ Insert 18333fig0107.png
169
+ Figure 1-7. Git OS X installer
170
+
171
+ The other major way is to install Git via MacPorts (`http://www.macports.org`). If you have MacPorts installed, install Git via
172
+
173
+ $ sudo port install git-core +svn +doc +bash_completion +gitweb
174
+
175
+ You don’t have to add all the extras, but you’ll probably want to include +svn in case you ever have to use Git with Subversion repositories (see Chapter 8).
176
+
177
+ ### Installing on Windows ###
178
+
179
+ Installing Git on Windows is very easy. The msysGit project has one of the easier installation procedures. Simply download the installer exe file from the GitHub page, and run it:
180
+
181
+ http://msysgit.github.com/
182
+
183
+ After it’s installed, you have both a command-line version (including an SSH client that will come in handy later) and the standard GUI.
184
+
185
+ ## First-Time Git Setup ##
186
+
187
+ Now that you have Git on your system, you’ll want to do a few things to customize your Git environment. You should have to do these things only once; they’ll stick around between upgrades. You can also change them at any time by running through the commands again.
188
+
189
+ Git comes with a tool called git config that lets you get and set configuration variables that control all aspects of how Git looks and operates. These variables can be stored in three different places:
190
+
191
+ * `/etc/gitconfig` file: Contains values for every user on the system and all their repositories. If you pass the option` --system` to `git config`, it reads and writes from this file specifically.
192
+ * `~/.gitconfig` file: Specific to your user. You can make Git read and write to this file specifically by passing the `--global` option.
193
+ * config file in the git directory (that is, `.git/config`) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in `.git/config` trump those in `/etc/gitconfig`.
194
+
195
+ On Windows systems, Git looks for the `.gitconfig` file in the `$HOME` directory (`C:\Documents and Settings\$USER` for most people). It also still looks for /etc/gitconfig, although it’s relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer.
196
+
197
+ ### Your Identity ###
198
+
199
+ The first thing you should do when you install Git is to set your user name and e-mail address. This is important because every Git commit uses this information, and it’s immutably baked into the commits you pass around:
200
+
201
+ $ git config --global user.name "John Doe"
202
+ $ git config --global user.email johndoe@example.com
203
+
204
+ Again, you need to do this only once if you pass the `--global` option, because then Git will always use that information for anything you do on that system. If you want to override this with a different name or e-mail address for specific projects, you can run the command without the `--global` option when you’re in that project.
205
+
206
+ ### Your Editor ###
207
+
208
+ Now that your identity is set up, you can configure the default text editor that will be used when Git needs you to type in a message. By default, Git uses your system’s default editor, which is generally Vi or Vim. If you want to use a different text editor, such as Emacs, you can do the following:
209
+
210
+ $ git config --global core.editor emacs
211
+
212
+ ### Your Diff Tool ###
213
+
214
+ Another useful option you may want to configure is the default diff tool to use to resolve merge conflicts. Say you want to use vimdiff:
215
+
216
+ $ git config --global merge.tool vimdiff
217
+
218
+ Git accepts kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools. You can also set up a custom tool; see Chapter 7 for more information about doing that.
219
+
220
+ ### Checking Your Settings ###
221
+
222
+ If you want to check your settings, you can use the `git config --list` command to list all the settings Git can find at that point:
223
+
224
+ $ git config --list
225
+ user.name=Scott Chacon
226
+ user.email=schacon@gmail.com
227
+ color.status=auto
228
+ color.branch=auto
229
+ color.interactive=auto
230
+ color.diff=auto
231
+ ...
232
+
233
+ You may see keys more than once, because Git reads the same key from different files (`/etc/gitconfig` and `~/.gitconfig`, for example). In this case, Git uses the last value for each unique key it sees.
234
+
235
+ You can also check what Git thinks a specific key’s value is by typing `git config {key}`:
236
+
237
+ $ git config user.name
238
+ Scott Chacon
239
+
240
+ ## Getting Help ##
241
+
242
+ If you ever need help while using Git, there are three ways to get the manual page (manpage) help for any of the Git commands:
243
+
244
+ $ git help <verb>
245
+ $ git <verb> --help
246
+ $ man git-<verb>
247
+
248
+ For example, you can get the manpage help for the config command by running
249
+
250
+ $ git help config
251
+
252
+ These commands are nice because you can access them anywhere, even offline.
253
+ If the manpages and this book aren’t enough and you need in-person help, you can try the `#git` or `#github` channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.
254
+
255
+ ## Summary ##
256
+
257
+ You should have a basic understanding of what Git is and how it’s different from the CVCS you may have been using. You should also now have a working version of Git on your system that’s set up with your personal identity. It’s now time to learn some Git basics.
@@ -0,0 +1,1127 @@
1
+ # Git Basics #
2
+
3
+ Si solo pudieras leer un capítulo de este libro para poder trabajar con Git, este es él capítulo. Este capítulo cobre todos los comandos básicos que son necesarios para la vasta mayoría de tareas que eventualmente ocuparán tu tiempo cuando trabajes con Git. Para el final del capítulo, deberías ser capaz de configurar e inicializar un repositorio, iniciar y detener el seguimiento de archivos, y 'stage' y commitear los cambios. También te mostraremos cómo configurar Git para que ignore determinados archivos y patrones de nombres para los archivos, como desahacer equivocaciones rápida y sencillamente, como navegador por el historial de tu proyecto y ver los cambios entre cada commit, y cómo empujar y 'pull' desde repositorios remotos.
4
+
5
+ ## Obteniendo un Repositorio Git ##
6
+
7
+ Tu puedes obtener un proyecto basado en Git utilizando dos métodos principales. El primero consiste en tomar un proyecto existente e importarlo dentro de Git. El segundo se basa en clonar un repositorio Git desde otro servidor.
8
+
9
+ ### Inicializando un Repositorio Dentro de un Directorio Preexistente ###
10
+
11
+ Si quisieramos comenzar a realizar un seguimiento de un proyecto con Git, lo que necesitamos es ir al directorio del proyecto y tipear
12
+
13
+ $ git init
14
+
15
+ Esta acción creará un nuevo subdirectorio llamado .git que contendrá todos los archivos necesarios por el repositorio (el esqueleto básico de un repositorio Git). En este punto, nada en el proyecto está siendo rastreado aún. (Revisa el Capítulo 9 para mayor información acerca de qué archivo son contenidos exáctamente dentro del directorio `.git` que acaba de ser creado.)
16
+
17
+ Si quisieramos comenzar a llevar un control de versiones de los archivos existentes (en contraposición con un directorio vacío), entonces probablemente queramos comenzar a realizar un seguimiento de los archivos del directorio y realizar un commit inicial de los mismos. Puedes lograr esto con unos pocos comandos de git que especifican los archivos sobre los que quieres realizar un seguimientos, seguidos por un commit:
18
+
19
+ $ git add *.c
20
+ $ git add README
21
+ $ git commit –m 'initial project version'
22
+
23
+ Volveremos sobre estos mismos comandos en solo un minuto. En este punto, ya tienes un repositorio Git con archivos versionados en el mismo y un commit inicial.
24
+
25
+ ### Clonando un Repositorio Existente ###
26
+
27
+ Si quisieras obtener una copia de un repositorio Git existente (por ejemplo, de un projecto con el cuál quieres contribuir) el comando que estás buscando es git clone. Si eres familiar con otros sistemas VCS como Subversion, notarás que el comando se llama clone y no checkout. Esta es una distinción muy importante, Git recibe una copia de casi todos los datos que el servidor posee. Cada version de cada archivo de la historia del proyecto es descargado cuando ejecutas `git clone`. De hecho, si el disco del servidor se corrompiera, puede usar cualquiera de los clones de cualquiera de los clientes para restaurar el estado del servidor de nuevo al estado en que estaba cuando fue clonado (es posible que se pierdan algunos de los hooks ubicados en el servidor y configuraciones por el estilo, pero toda la información versionada estará ahí; revisa el Capítulo 4 para más detalles.)
28
+
29
+ Clonarás un repositorio con el comando `git clone [url]`. Por ejemplo, si quisieras clonar la librería de Git en Ruby llamada Grit, puedes hacer lo siguiente:
30
+
31
+ $ git clone git://github.com/schacon/grit.git
32
+
33
+ Esta acción creará un directorio llamado "grit", inicializará el directorio `.git` dentro del mismo, descargará toda la información del repositorio, y generará una copia de trabajo de la última versión. Si ingresas al nuevo directorio recién creado `grit`, verás que se encuentran dentro del mismo todos los archivos, listos para ser trabajados o utilizados. Si quieres clonar un repositorio en un directorio que se llama de otra forma en lugar de grit, puedes especificar el comando de la siguiente forma:
34
+
35
+ $ git clone git://github.com/schacon/grit.git mygrit
36
+
37
+ Este comando hace lo mismo que el comando anterior pero el nombre del directorio destino será mygrit.
38
+
39
+ Git tiene un número de protocoles diferentes que pueden ser utilizados. En los ejemplos previos utilizamos el protocolo `git://` pero también será normal observar los protocolos `http(s)://` or `usuario@servidor:/path.git`, que utiliza el protocolo SSH de transferencia. En el Capítulo 4 se introducirán todas las opciones disponibles con las cuáles un servidor puede ser configurado para el acceso al repositorio Git y las ventajas y las desventajas de cada una de ellas.
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
+ Fig 2-1. The lifecycle of the status of your files
51
+
52
+ ### Revisando el Estado de Tus Archivos ###
53
+
54
+ La herramienta principal que se utiliza para determinar qué archivos están en qué estados es el comando git status. Si ejecutas este comando inmediatamente después de realizar una clonación, deberías visualizar una salida similar a la siguiente:
55
+
56
+ $ git status
57
+ # On branch master
58
+ nothing to commit, working directory clean
59
+
60
+ Esto significa que tienes una copia de trabajo limpia, en otras palabras, que no hay ningún archivo versionado que haya sido modificado. Git tampoco detectó ningún archivo sin versionar, de otra manera debería estar listado aquí. Por último, el comando indica en qué branch estás trabajando. Por ahora, siempre será master, que es el branch por defecto; no hace falta que te preocupes por saber qué significa en este punto aún. En el próximo capítulo analizaremos los branches y referencias en detalle.
61
+
62
+ Supongamos que agregas un nuevo archivo al proyecto, uno simple que se llame README. Si el archivo no existía con anterioridad, al ejecutar el comando `git status`, verás los archivos sin versionar de la siguiente forma:
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
+ nothing added to commit but untracked files present (use "git add" to track)
72
+
73
+ Podemos saber que el nuevo archivo llamado README aún no ha sido versionado gracias que aparece listado debajo de la cabecera "Untracked files" en la salida del comando. Sin versionar significa que Git notó que el archivo no existía en el snapshot previo (commit); Git no comenzará a incluirlo hasta que explícitamente le digamos que debe hacerlo. Lo hace de esta forma para evitar que accidentalmente comiencen a ser versionados archivos binarios generados por otros procesos u otros tipos de archivos que no deberían ser incluidos. Nosotros sí queremos que el archivo README sea versionado, así que le indicaremos q Git que comience el seguimiento del mismo.
74
+
75
+ ### Versionando Archivos Nuevos ###
76
+
77
+ Para versionar un archivo nuevo, puedes utilizar el comando `git add`. Para comenzar a versionar el archivo llamado README, puede ejecutar el siguiente comando:
78
+
79
+ $ git add README
80
+
81
+ Si ejecutas el comando de estado nuevamente, podrás notar que el archivo README ahora está versionado y 'estacionado':
82
+
83
+ $ git status
84
+ # On branch master
85
+ # Changes to be committed:
86
+ # (use "git reset HEAD <file>..." to unstage)
87
+ #
88
+ # new file: README
89
+ #
90
+
91
+ Se puede decir que el archivo está estacionado debido a que está debajo de la cabecera “Changes to be committed” (“Cambios que será commiteados”). Si realizas un commit en este punto, la versión del archivo al momento en que ejecutaste el comando git add estará en el snapshot histórico. Si recuerdas el momento en que ejecutaste git init en las secciones anteriores, podrás recordas que también ejecutaste git add (nombre de los archivos), esto se realizo de esa manera para versionar todos los archivos que estaban dentro del directorio. El comando git add puede aceptar como parámetro tanto el nombre de un archivo como el nombre de un directorio; si es un directorio, el comando agregará todos los archivos dentro del mismo de forma recursiva.
92
+
93
+ ### Estacionando Archivos Modificados ###
94
+
95
+ Vamos a modificar el contenido de algunos archivos que ya han sido versionados. Si realizar una modificación en el archivo versionado con anterioridad que se llama 'benchmarks.rb' y luego ejecutas el comando de estado nuevamente, obtendrás algo similar a lo siguiente:
96
+
97
+ $ git status
98
+ # On branch master
99
+ # Changes to be committed:
100
+ # (use "git reset HEAD <file>..." to unstage)
101
+ #
102
+ # new file: README
103
+ #
104
+ # Changes not staged for commit:
105
+ # (use "git add <file>..." to update what will be committed)
106
+ #
107
+ # modified: benchmarks.rb
108
+ #
109
+
110
+ 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:
111
+ El archivo benchmarks.rb aparece debajo de una sección denominada “Changes not staged for commit” (“Modificada pero no actualizada”), que significa que el archivo versionado ha sido modificado en el directorio de trabajo pero todavía no ha sido estacionado.
112
+
113
+ $ git add benchmarks.rb
114
+ $ git status
115
+ # On branch master
116
+ # Changes to be committed:
117
+ # (use "git reset HEAD <file>..." to unstage)
118
+ #
119
+ # new file: README
120
+ # modified: benchmarks.rb
121
+ #
122
+
123
+ Ambos archivos están estacionados y serán enviados en el próximo commit. En este punto, supongamos que recuerdas realizar una pequeña modificación que querías realizar al archivo benchmarks.rb antes de commitearlo. Abres de nuevo el archivo y realizas la modificación, y estás listo para commitear. Sin embargo, antes corramos el comando `git status` una vez más:
124
+
125
+ $ vim benchmarks.rb
126
+ $ git status
127
+ # On branch master
128
+ # Changes to be committed:
129
+ # (use "git reset HEAD <file>..." to unstage)
130
+ #
131
+ # new file: README
132
+ # modified: benchmarks.rb
133
+ #
134
+ # Changes not staged for commit:
135
+ # (use "git add <file>..." to update what will be committed)
136
+ #
137
+ # modified: benchmarks.rb
138
+ #
139
+
140
+ ¿Qué es lo que ha sucedido? Ahora el archivo benchmarks.rb está marcado como estacionado y no estacionado. ¿Cómo es esto posible? Resulta que Git estaciona el archivo exactamente como lo encuentra cuando ejecutas el comando git add. Si realizas el commit en este momento, la versión que Git encontré cuando ejecutaste el comando git add es lo que irá en el contenido del commit, no la versión que como aparece en tu copia de trabajo luego de que realizaras la última modificación. Si modificas un archivo luego de ejecutar el comando `git add`, tendrás que volver a ejecutarlo para estacionar los cambios de la última versión del archivo:
141
+
142
+ $ git add benchmarks.rb
143
+ $ git status
144
+ # On branch master
145
+ # Changes to be committed:
146
+ # (use "git reset HEAD <file>..." to unstage)
147
+ #
148
+ # new file: README
149
+ # modified: benchmarks.rb
150
+ #
151
+
152
+ ### Ignorando Archivos ###
153
+
154
+ A menudo, habrá determinado tipo de archivos que no querrás que Git automáticamente agregue o siquiera que te los muestre como no versionados. Estos archivos son generalmente generados automáticamente, como suelen ser archivos de log o archivos generados por procesos de compilación. En estos casos, puedes crear un archivo listando los patrones de nombre que quieren que sean ignorados y nombrar este archivo .gitignor. A continuación encontrarás un ejemplo de un archivot .gitignore:
155
+
156
+ $ cat .gitignore
157
+ *.[oa]
158
+ *~
159
+
160
+ La primer línea le indica a Git que ignore cualquier archivo que finalice con .o o .a, archivos objeto que suelen ser el producto de procesos de compilación de código fuente. La segunda línea le indica a Git que ignore todos los archivos que finalizan con una tild (`~`), como los que son utilizados por muchos editores de textos como archivos temporales; y demás. Configurar un archivo .gitignore antes de comenzar a trabajar suele ser por lo general una buena idea para evitar que accidentalmente commitees archivos que realmente no quieres que estén en tu repositorio Git.
161
+
162
+ Las reglas para los patrones que pueden ser incluidos en el archivo .gitignore son:
163
+
164
+ * Las líneas en blanco o que comienzan con # son ignoradas.
165
+ * Standard glob patterns work.
166
+ * You can end patterns with a forward slash (`/`) to specify a directory.
167
+ * Puedes especificar un directorio agregando un barra (`/`) al final del patrón.
168
+ * You can negate a pattern by starting it with an exclamation point (`!`).
169
+ * Puedes negar un patrón anteponiéndole un signo de exclamación (`!`) al principio.
170
+
171
+ Los patrones globales son expresiones regulares simplificadas que pueden ser utilizadas por el shell. Un asterisco (`*`) reconoce creo o más caracteres; `[abc]` reconoce cualquier caracter que se encuentre entre los corchetes; un signo de pregunta cerrado (`?`) reconoce un caracter y caracteres separados por un guión encerrados entres corchetes (`[0-9]`) reconoce cualquier caracter que se encuentre entre ellos (en este caso de 0 a 9).
172
+
173
+ Aquí hay otro ejemplo de un archivo .gitignore:
174
+
175
+ # un comentario - es ignorado
176
+ # ningún archivo .a
177
+ *.a
178
+ # pero si queremos versionar el archivo lib.a, incluse aunque estemos ignorando los archivos .a más arriba
179
+ !lib.a
180
+ # solo ignorar el archivo TODO del directorio raíz, no de los subdirectorios
181
+ /TODO
182
+ # ignorar todos los archivos dentro del directorio build/
183
+ build/
184
+ # ignorar el archivo doc/notes.txt, pero no doc/server/arch.txt
185
+ doc/*.txt
186
+
187
+ ### Visualizando Archivos Versionados y No Versionados ###
188
+
189
+ Si el comando `git status` es demasiado vago para tí (quieres saber exactamente qué es lo que has cambiado, no solo los archivos que han cambiado) puede utilizar el comando `git diff`. Cubriremos el comando `git diff` en más detalle luego, pero lo más probable es que generalmente lo utilicemos para responder estas dos preguntas: ¿Qué es lo que has cambiado pero aún no has estacionado? y ¿Qué has estacionado que está a punto de ser commiteado? Aunque el comando `git status` responde esta pregunta de forma bastante general, `git diff` muestra exactamente qué línea ha sido añadida o removida, el parche, como se lo suele llamar.
190
+
191
+ Supongamos que quieres editar y estacionar el archivo README de nuevo y luego editar el archivo benchmarks.rb sin salvarlo. Si ejecutas el comando `status`, de nuevo verás algo como lo siguiente:
192
+
193
+ $ git status
194
+ # On branch master
195
+ # Changes to be committed:
196
+ # (use "git reset HEAD <file>..." to unstage)
197
+ #
198
+ # new file: README
199
+ #
200
+ # Changes not staged for commit:
201
+ # (use "git add <file>..." to update what will be committed)
202
+ #
203
+ # modified: benchmarks.rb
204
+ #
205
+
206
+ Para ver qué es lo que has cambiado pero aún no has estacionado, tipea `git diff` sin más argumentos:
207
+
208
+ $ git diff
209
+ diff --git a/benchmarks.rb b/benchmarks.rb
210
+ index 3cb747f..da65585 100644
211
+ --- a/benchmarks.rb
212
+ +++ b/benchmarks.rb
213
+ @@ -36,6 +36,10 @@ def main
214
+ @commit.parents[0].parents[0].parents[0]
215
+ end
216
+
217
+ + run_code(x, 'commits 1') do
218
+ + git.commits.size
219
+ + end
220
+ +
221
+ run_code(x, 'commits 2') do
222
+ log = git.commits('master', 15)
223
+ log.size
224
+
225
+ Este comando compara qué se encuentra en tu copia de trabajo con lo que se encuentra en tu área de estacionamiento. El resultado muestra los cambios que has realizado pero aún no has estacionado.
226
+
227
+ Si quisieras ver qué es lo que está estacionado y será enviado en el próximo commit, puedes utilizar el comando `git diff --cached`. (En versiones de Git posteriores a la 1.6.1 también puedes utilizar el comando `git diff --staged`, que es más fácil de recordar.) Este comando compara los cambios estacionados con tu último commit:
228
+
229
+ $ git diff --cached
230
+ diff --git a/README b/README
231
+ new file mode 100644
232
+ index 0000000..03902a1
233
+ --- /dev/null
234
+ +++ b/README2
235
+ @@ -0,0 +1,5 @@
236
+ +grit
237
+ + by Tom Preston-Werner, Chris Wanstrath
238
+ + http://github.com/mojombo/grit
239
+ +
240
+ +Grit is a Ruby library for extracting information from a Git repository
241
+
242
+ Es importante notar que `git diff` por si mismo no muestra todos los cambios realizados desde tu último commit, solo los cambios que aún no han sido estacionados. Esto puede resultar confuso, ya que si has estacionado todos los cambio, `git diff` no mostrará ninguna información en su salida.
243
+
244
+ Para poner otro ejemplo, si estacionas el archivo benchmarks.rb y luego lo editas, puedes utilizar el comando `git diff` para ver los cambios en el archivo que están estacionados y los cambios que no están estacionados:
245
+
246
+ $ git add benchmarks.rb
247
+ $ echo '# test line' >> benchmarks.rb
248
+ $ git status
249
+ # On branch master
250
+ #
251
+ # Changes to be committed:
252
+ #
253
+ # modified: benchmarks.rb
254
+ #
255
+ # Changes not staged for commit:
256
+ #
257
+ # modified: benchmarks.rb
258
+ #
259
+
260
+ Ahora puedes utilizar `git diff` para ver qué es lo que no ha sido estacionado aún
261
+
262
+ $ git diff
263
+ diff --git a/benchmarks.rb b/benchmarks.rb
264
+ index e445e28..86b2f7c 100644
265
+ --- a/benchmarks.rb
266
+ +++ b/benchmarks.rb
267
+ @@ -127,3 +127,4 @@ end
268
+ main()
269
+
270
+ ##pp Grit::GitRuby.cache_client.stats
271
+ +# test line
272
+ and git diff --cached to see what you’ve staged so far:
273
+ $ git diff --cached
274
+ diff --git a/benchmarks.rb b/benchmarks.rb
275
+ index 3cb747f..e445e28 100644
276
+ --- a/benchmarks.rb
277
+ +++ b/benchmarks.rb
278
+ @@ -36,6 +36,10 @@ def main
279
+ @commit.parents[0].parents[0].parents[0]
280
+ end
281
+
282
+ + run_code(x, 'commits 1') do
283
+ + git.commits.size
284
+ + end
285
+ +
286
+ run_code(x, 'commits 2') do
287
+ log = git.commits('master', 15)
288
+ log.size
289
+
290
+ ### Enviando Los Cambios ###
291
+
292
+ Ahora que el area de estacionado está lista en la forma en que uno lo deseaba, puedes enviar tus cambios. Recuerdo que cualquier cosa que aún no esté estacionada (cualquier archivo que hayas creado o editado pero sobre los cuáles aún no hayas ejecutado `git add` sobre ellos desde que los editaste) no irán en el siguiente envio. Se mantendrán como archivos modificados en tu disco.
293
+ En este caso, la última vez que ejecutaste `git status`, viste qué es lo que estaba estacionado, así que ya estás listo para enviar los cambios. La forma más simple de enviar los cambios es tipear `git commit`:
294
+
295
+ $ git commit
296
+
297
+ Al hacerlo, se iniciará un editor de textos de tu gusto. (Esto se logra configurando la variable de entorno `$EDITOR` de tu shell, usualmente es vim o emacs, aunque puedes configurar su valor utilizando el comando `git config --global core.editor` como lo vimos en el Capítulo 1).
298
+
299
+ El editor presentará el siguiente texto (este es un ejemplo tomado de una pantalla de Vim):
300
+
301
+ # Please enter the commit message for your changes. Lines starting
302
+ # with '#' will be ignored, and an empty message aborts the commit.
303
+ # On branch master
304
+ # Changes to be committed:
305
+ # (use "git reset HEAD <file>..." to unstage)
306
+ #
307
+ # new file: README
308
+ # modified: benchmarks.rb
309
+ ~
310
+ ~
311
+ ~
312
+ ".git/COMMIT_EDITMSG" 10L, 283C
313
+
314
+ Como puedes ver, el mensaje de envio por defecto contiene la última salida del comando `git status` como comentario y una línea vacía arriba de todo. Puedes remover los comentarios y tipear tu propio mensaje para este envio, o puedes dejarlos para recordar qué es lo que estás enviando. (Para un mensaje recordatorio aún más explícito de qué es lo que has modificado, puedes añadir el argumento `-v` al comando `git commit`. Al hacelo también se agregará a los cambios presentes en el editor las diferencias de los cambios de manera que puedas saber exactamente qué cambiaste.) Cuando salgas del editor, Git creará un envio con el mensaje que acabas de redactar (junto con los comentarios y las diferencias).
315
+
316
+ También existe otra alternativa, puedes tipear el mensaje del envio junto con el comando `commit` especificando el parámetro -m, como se muestra a continuación:
317
+
318
+ $ git commit -m "Story 182: Fix benchmarks for speed"
319
+ [master]: created 463dc4f: "Fix benchmarks for speed"
320
+ 2 files changed, 3 insertions(+), 0 deletions(-)
321
+ create mode 100644 README
322
+
323
+ ¡Acabas de crear tu primer envio! Notarás que el comando `commit` generó cierta información como salida: a qué rama ha sido enviada (master), cuál es la verificación SHA-1 del envio (`463dc4f`), cuántos archivos han cambiado, y las estadísticas acerca de cuántas líneas han sido añadidas o removidas en el envio.
324
+
325
+ Recuerda que un envio registra la instantánea que preparaste en el área de estacionado. Nada que no hayas estacionado aún estará ahí, modificado; puedes hacer otro envio para agregarlo al historial. Cada vez que realizas un envío, estás generando una instantánea del proyecto que luego podrás utilizar para volver atrás o comparar.
326
+
327
+ ### Skipping the Staging Area ###
328
+
329
+ 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:
330
+
331
+ $ git status
332
+ # On branch master
333
+ #
334
+ # Changes not staged for commit:
335
+ #
336
+ # modified: benchmarks.rb
337
+ #
338
+ $ git commit -a -m 'added new benchmarks'
339
+ [master 83e38c7] added new benchmarks
340
+ 1 files changed, 5 insertions(+), 0 deletions(-)
341
+
342
+ Notice how you don’t have to run `git add` on the benchmarks.rb file in this case before you commit.
343
+
344
+ ### Eliminando Archivos ###
345
+
346
+ Para remover un archivo del repositorio Git, es necesario removerlo de los archivos versionados (para ser más exacto, removerlo del área de estacionado) y luego realizar un envío. El comando `git rm` hace exactamente esto y también remueve el archivo de tu copia de trabajo para que no esté presente como no versionado en el futuro.
347
+
348
+ Si simplemente eliminas el archivo de tu copia de trabajo, aparecerá bajo la sección "Changes not staged for commit" ("Modificado pero no actualizado", es decir, _no versionado_) cuando ejecutes el comando `git status`:
349
+
350
+ $ rm grit.gemspec
351
+ $ git status
352
+ # On branch master
353
+ #
354
+ # Changes not staged for commit:
355
+ # (use "git add/rm <file>..." to update what will be committed)
356
+ #
357
+ # deleted: grit.gemspec
358
+ #
359
+
360
+ Si entonces ejecutas el comando `git rm`, añade la eliminación del archivo al área de estacionado:
361
+
362
+ $ git rm grit.gemspec
363
+ rm 'grit.gemspec'
364
+ $ git status
365
+ # On branch master
366
+ #
367
+ # Changes to be committed:
368
+ # (use "git reset HEAD <file>..." to unstage)
369
+ #
370
+ # deleted: grit.gemspec
371
+ #
372
+
373
+ En el próximo envio, el archivo desaparecerá y no dejará de estar versionado. Si has modificado el archivo y lo has añadido al índice, deberás forzar la eliminación con el argumento `-f`. Esta es una medida de seguridad para prevenir la eliminación accidental de información que aún no ha sido versionada y que no podrá ser recuperada del repositorio Git.
374
+
375
+ Otro dato que te podrá resultar útil conocer es que puedes mantener un archivo en tu copia de trabajo pero puedes eliminarlo del área de estacionado. En otras palabras, puedes dejar el archivo en el disco dura pero evitar que Git lo versione. Esta funcionalidad es muy útil si olvidás añadir algo al archivo `.gitignore` y accidentalmente lo versionas, como podría ser un archivo de log muy extenso o un montón de archivo `.a` generados por un compilador. Para hacer uso de esta función, debes utilizar la opción `--cached` junto con el comando para eliminar un archivo:
376
+
377
+ $ git rm --cached readme.txt
378
+
379
+ El comando `git rm` también acepta tanto archivos como directorios o patrones globales. Esto signfica que puedes hacer cosas como las siguientes
380
+
381
+ $ git rm log/\*.log
382
+
383
+ Presta atención a la barra invertida (`\`) que está delante del `*`. Esta es necesaria debido a que Git realiza su propia expansión en los nombres de los archivo en adición a la que realiza el shell. Este comando elimina todos los archivos que tengan la extensión `.log` en el directorio `log/`. O puedes hacer algo como lo siguiente:
384
+
385
+ $ git rm \*~
386
+
387
+ Este comando elimina todos los archivos que finalizan en `~`.
388
+
389
+ ### Moving Files ###
390
+
391
+ 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.
392
+
393
+ 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
394
+
395
+ $ git mv file_from file_to
396
+
397
+ 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:
398
+
399
+ $ git mv README.txt README
400
+ $ git status
401
+ # On branch master
402
+ # Your branch is ahead of 'origin/master' by 1 commit.
403
+ #
404
+ # Changes to be committed:
405
+ # (use "git reset HEAD <file>..." to unstage)
406
+ #
407
+ # renamed: README.txt -> README
408
+ #
409
+
410
+ However, this is equivalent to running something like this:
411
+
412
+ $ mv README.txt README
413
+ $ git rm README.txt
414
+ $ git add README
415
+
416
+ 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.
417
+
418
+ ## Viewing the Commit History ##
419
+
420
+ 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.
421
+
422
+ These examples use a very simple project called simplegit that I often use for demonstrations. To get the project, run
423
+
424
+ git clone git://github.com/schacon/simplegit-progit.git
425
+
426
+ When you run `git log` in this project, you should get output that looks something like this:
427
+
428
+ $ git log
429
+ commit ca82a6dff817ec66f44342007202690a93763949
430
+ Author: Scott Chacon <schacon@gee-mail.com>
431
+ Date: Mon Mar 17 21:52:11 2008 -0700
432
+
433
+ changed the verison number
434
+
435
+ commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
436
+ Author: Scott Chacon <schacon@gee-mail.com>
437
+ Date: Sat Mar 15 16:40:33 2008 -0700
438
+
439
+ removed unnecessary test code
440
+
441
+ commit a11bef06a3f659402fe7563abf99ad00de2209e6
442
+ Author: Scott Chacon <schacon@gee-mail.com>
443
+ Date: Sat Mar 15 10:31:28 2008 -0700
444
+
445
+ first commit
446
+
447
+ 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.
448
+
449
+ 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.
450
+
451
+ 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:
452
+
453
+ $ git log –p -2
454
+ commit ca82a6dff817ec66f44342007202690a93763949
455
+ Author: Scott Chacon <schacon@gee-mail.com>
456
+ Date: Mon Mar 17 21:52:11 2008 -0700
457
+
458
+ changed the verison number
459
+
460
+ diff --git a/Rakefile b/Rakefile
461
+ index a874b73..8f94139 100644
462
+ --- a/Rakefile
463
+ +++ b/Rakefile
464
+ @@ -5,7 +5,7 @@ require 'rake/gempackagetask'
465
+ spec = Gem::Specification.new do |s|
466
+ - s.version = "0.1.0"
467
+ + s.version = "0.1.1"
468
+ s.author = "Scott Chacon"
469
+
470
+ commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
471
+ Author: Scott Chacon <schacon@gee-mail.com>
472
+ Date: Sat Mar 15 16:40:33 2008 -0700
473
+
474
+ removed unnecessary test code
475
+
476
+ diff --git a/lib/simplegit.rb b/lib/simplegit.rb
477
+ index a0a60ae..47c6340 100644
478
+ --- a/lib/simplegit.rb
479
+ +++ b/lib/simplegit.rb
480
+ @@ -18,8 +18,3 @@ class SimpleGit
481
+ end
482
+
483
+ end
484
+ -
485
+ -if $0 == __FILE__
486
+ - git = SimpleGit.new
487
+ - puts git.show
488
+ -end
489
+
490
+
491
+ 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.
492
+ 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:
493
+
494
+ $ git log --stat
495
+ commit ca82a6dff817ec66f44342007202690a93763949
496
+ Author: Scott Chacon <schacon@gee-mail.com>
497
+ Date: Mon Mar 17 21:52:11 2008 -0700
498
+
499
+ changed the verison number
500
+
501
+ Rakefile | 2 +-
502
+ 1 files changed, 1 insertions(+), 1 deletions(-)
503
+
504
+ commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
505
+ Author: Scott Chacon <schacon@gee-mail.com>
506
+ Date: Sat Mar 15 16:40:33 2008 -0700
507
+
508
+ removed unnecessary test code
509
+
510
+ lib/simplegit.rb | 5 -----
511
+ 1 files changed, 0 insertions(+), 5 deletions(-)
512
+
513
+ commit a11bef06a3f659402fe7563abf99ad00de2209e6
514
+ Author: Scott Chacon <schacon@gee-mail.com>
515
+ Date: Sat Mar 15 10:31:28 2008 -0700
516
+
517
+ first commit
518
+
519
+ README | 6 ++++++
520
+ Rakefile | 23 +++++++++++++++++++++++
521
+ lib/simplegit.rb | 25 +++++++++++++++++++++++++
522
+ 3 files changed, 54 insertions(+), 0 deletions(-)
523
+
524
+ 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.
525
+ 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:
526
+
527
+ $ git log --pretty=oneline
528
+ ca82a6dff817ec66f44342007202690a93763949 changed the verison number
529
+ 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 removed unnecessary test code
530
+ a11bef06a3f659402fe7563abf99ad00de2209e6 first commit
531
+
532
+ 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:
533
+
534
+ $ git log --pretty=format:"%h - %an, %ar : %s"
535
+ ca82a6d - Scott Chacon, 11 months ago : changed the verison number
536
+ 085bb3b - Scott Chacon, 11 months ago : removed unnecessary test code
537
+ a11bef0 - Scott Chacon, 11 months ago : first commit
538
+
539
+ Table 2-1 lists some of the more useful options that format takes.
540
+
541
+ Option Description of Output
542
+ %H Commit hash
543
+ %h Abbreviated commit hash
544
+ %T Tree hash
545
+ %t Abbreviated tree hash
546
+ %P Parent hashes
547
+ %p Abbreviated parent hashes
548
+ %an Author name
549
+ %ae Author e-mail
550
+ %ad Author date (format respects the –date= option)
551
+ %ar Author date, relative
552
+ %cn Committer name
553
+ %ce Committer email
554
+ %cd Committer date
555
+ %cr Committer date, relative
556
+ %s Subject
557
+
558
+ You may be wondering what the difference is between _author_ and _committer_. The author is the person who originally wrote the work, whereas the committer is the person who last applied the work. 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.
559
+
560
+ 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 our copy of the Grit project repository:
561
+
562
+ $ git log --pretty=format:"%h %s" --graph
563
+ * 2d3acf9 ignore errors from SIGCHLD on trap
564
+ * 5e3ee11 Merge branch 'master' of git://github.com/dustin/grit
565
+ |\
566
+ | * 420eac9 Added a method for getting the current branch.
567
+ * | 30e367c timeout code and tests
568
+ * | 5a09431 add timeout protection to grit
569
+ * | e1193f8 support for heads with slashes in them
570
+ |/
571
+ * d6016bc require time for xmlschema
572
+ * 11d191e Merge branch 'defunkt' into local
573
+
574
+ 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.
575
+
576
+ Option Description
577
+ -p Show the patch introduced with each commit.
578
+ --stat Show statistics for files modified in each commit.
579
+ --shortstat Display only the changed/insertions/deletions line from the --stat command.
580
+ --name-only Show the list of files modified after the commit information.
581
+ --name-status Show the list of files affected with added/modified/deleted information as well.
582
+ --abbrev-commit Show only the first few characters of the SHA-1 checksum instead of all 40.
583
+ --relative-date Display the date in a relative format (for example, “2 weeks ago”) instead of using the full date format.
584
+ --graph Display an ASCII graph of the branch and merge history beside the log output.
585
+ --pretty Show commits in an alternate format. Options include oneline, short, full, fuller, and format (where you specify your own format).
586
+
587
+ ### Limiting Log Output ###
588
+
589
+ 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 show 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.
590
+
591
+ 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:
592
+
593
+ $ git log --since=2.weeks
594
+
595
+ 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”.
596
+
597
+ 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 want to specify both author and grep options, you have to add `--all-match` or the command will match commits with either.)
598
+
599
+ 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.
600
+
601
+ In Table 2-3 we’ll list these and a few other common options for your reference.
602
+
603
+ Option Description
604
+ -(n) Show only the last n commits
605
+ --since, --after Limit the commits to those made after the specified date.
606
+ --until, --before Limit the commits to those made before the specified date.
607
+ --author Only show commits in which the author entry matches the specified string.
608
+ --committer Only show commits in which the committer entry matches the specified string.
609
+
610
+ For example, if you want to see which commits modifying test files in the Git source code history were committed by Junio Hamano and were not merges in the month of October 2008, you can run something like this:
611
+
612
+ $ git log --pretty="%h:%s" --author=gitster --since="2008-10-01" \
613
+ --before="2008-11-01" --no-merges -- t/
614
+ 5610e3b - Fix testcase failure when extended attribute
615
+ acd3b9e - Enhance hold_lock_file_for_{update,append}()
616
+ f563754 - demonstrate breakage of detached checkout wi
617
+ d1a43f2 - reset --hard/read-tree --reset -u: remove un
618
+ 51a94af - Fix "checkout --track -b newbranch" on detac
619
+ b0ad11e - pull: allow "git pull origin $something:$cur
620
+
621
+ Of the nearly 20,000 commits in the Git source code history, this command shows the 6 that match those criteria.
622
+
623
+ ### Using a GUI to Visualize History ###
624
+
625
+ 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.
626
+
627
+ Insert 18333fig0202.png
628
+ Figure 2-2. The gitk history visualizer
629
+
630
+ 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.
631
+
632
+ ## Undoing Things ##
633
+
634
+ 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 undo some of these undos. This is one of the few areas in Git where you may lose some work if you do it wrong.
635
+
636
+ ### Changing Your Last Commit ###
637
+
638
+ 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:
639
+
640
+ $ git commit --amend
641
+
642
+ This command takes your staging area and uses it for the commit. If you’ve have made no changes since your last commit (for instance, you run this command it immediately after your previous commit), then your snapshot will look exactly the same and all you’ll change is your commit message.
643
+
644
+ 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.
645
+
646
+ 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:
647
+
648
+ $ git commit -m 'initial commit'
649
+ $ git add forgotten_file
650
+ $ git commit --amend
651
+
652
+ All three of these commands end up with a single commit — the second command replaces the results of the first.
653
+
654
+ ### Unstaging a Staged File ###
655
+
656
+ 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:
657
+
658
+ $ git add .
659
+ $ git status
660
+ # On branch master
661
+ # Changes to be committed:
662
+ # (use "git reset HEAD <file>..." to unstage)
663
+ #
664
+ # modified: README.txt
665
+ # modified: benchmarks.rb
666
+ #
667
+
668
+ 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:
669
+
670
+ $ git reset HEAD benchmarks.rb
671
+ benchmarks.rb: locally modified
672
+ $ git status
673
+ # On branch master
674
+ # Changes to be committed:
675
+ # (use "git reset HEAD <file>..." to unstage)
676
+ #
677
+ # modified: README.txt
678
+ #
679
+ # Changes not staged for commit:
680
+ # (use "git add <file>..." to update what will be committed)
681
+ # (use "git checkout -- <file>..." to discard changes in working directory)
682
+ #
683
+ # modified: benchmarks.rb
684
+ #
685
+
686
+ The command is a bit strange, but it works. The benchmarks.rb file is modified but once again unstaged.
687
+
688
+ ### Unmodifying a Modified File ###
689
+
690
+ 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:
691
+
692
+ # Changes not staged for commit:
693
+ # (use "git add <file>..." to update what will be committed)
694
+ # (use "git checkout -- <file>..." to discard changes in working directory)
695
+ #
696
+ # modified: benchmarks.rb
697
+ #
698
+
699
+ 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:
700
+
701
+ $ git checkout -- benchmarks.rb
702
+ $ git status
703
+ # On branch master
704
+ # Changes to be committed:
705
+ # (use "git reset HEAD <file>..." to unstage)
706
+ #
707
+ # modified: README.txt
708
+ #
709
+
710
+ 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.
711
+
712
+ 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.
713
+
714
+ ## Working with Remotes ##
715
+
716
+ 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.
717
+ 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.
718
+
719
+ ### Showing Your Remotes ###
720
+
721
+ 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:
722
+
723
+ $ git clone git://github.com/schacon/ticgit.git
724
+ Initialized empty Git repository in /private/tmp/ticgit/.git/
725
+ remote: Counting objects: 595, done.
726
+ remote: Compressing objects: 100% (269/269), done.
727
+ remote: Total 595 (delta 255), reused 589 (delta 253)
728
+ Receiving objects: 100% (595/595), 73.31 KiB | 1 KiB/s, done.
729
+ Resolving deltas: 100% (255/255), done.
730
+ $ cd ticgit
731
+ $ git remote
732
+ origin
733
+
734
+ You can also specify `-v`, which shows you the URL that Git has stored for the shortname to be expanded to:
735
+
736
+ $ git remote -v
737
+ origin git://github.com/schacon/ticgit.git
738
+
739
+ If you have more than one remote, the command lists them all. For example, my Grit repository looks something like this.
740
+
741
+ $ cd grit
742
+ $ git remote -v
743
+ bakkdoor git://github.com/bakkdoor/grit.git
744
+ cho45 git://github.com/cho45/grit.git
745
+ defunkt git://github.com/defunkt/grit.git
746
+ koke git://github.com/koke/grit.git
747
+ origin git@github.com:mojombo/grit.git
748
+
749
+ This means we 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).
750
+
751
+ ### Adding Remote Repositories ###
752
+
753
+ 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]`:
754
+
755
+ $ git remote
756
+ origin
757
+ $ git remote add pb git://github.com/paulboone/ticgit.git
758
+ $ git remote -v
759
+ origin git://github.com/schacon/ticgit.git
760
+ pb git://github.com/paulboone/ticgit.git
761
+
762
+ 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:
763
+
764
+ $ git fetch pb
765
+ remote: Counting objects: 58, done.
766
+ remote: Compressing objects: 100% (41/41), done.
767
+ remote: Total 44 (delta 24), reused 1 (delta 0)
768
+ Unpacking objects: 100% (44/44), done.
769
+ From git://github.com/paulboone/ticgit
770
+ * [new branch] master -> pb/master
771
+ * [new branch] ticgit -> pb/ticgit
772
+
773
+ 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.
774
+
775
+ ### Fetching and Pulling from Your Remotes ###
776
+
777
+ As you just saw, to get data from your remote projects, you can run
778
+
779
+ $ git fetch [remote-name]
780
+
781
+ 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.)
782
+
783
+ If you cloned 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.
784
+
785
+ 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.
786
+
787
+ ### Pushing to Your Remotes ###
788
+
789
+ 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:
790
+
791
+ $ git push origin master
792
+
793
+ 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.
794
+
795
+ ### Inspecting a Remote ###
796
+
797
+ 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:
798
+
799
+ $ git remote show origin
800
+ * remote origin
801
+ URL: git://github.com/schacon/ticgit.git
802
+ Remote branch merged with 'git pull' while on branch master
803
+ master
804
+ Tracked remote branches
805
+ master
806
+ ticgit
807
+
808
+ 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.
809
+
810
+ 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`:
811
+
812
+ $ git remote show origin
813
+ * remote origin
814
+ URL: git@github.com:defunkt/github.git
815
+ Remote branch merged with 'git pull' while on branch issues
816
+ issues
817
+ Remote branch merged with 'git pull' while on branch master
818
+ master
819
+ New remote branches (next fetch will store in remotes/origin)
820
+ caching
821
+ Stale tracking branches (use 'git remote prune')
822
+ libwalker
823
+ walker2
824
+ Tracked remote branches
825
+ acl
826
+ apiv2
827
+ dashboard2
828
+ issues
829
+ master
830
+ postgres
831
+ Local branch pushed with 'git push'
832
+ master:master
833
+
834
+ 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`.
835
+
836
+ ### Removing and Renaming Remotes ###
837
+
838
+ 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`:
839
+
840
+ $ git remote rename pb paul
841
+ $ git remote
842
+ origin
843
+ paul
844
+
845
+ 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`.
846
+
847
+ 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`:
848
+
849
+ $ git remote rm paul
850
+ $ git remote
851
+ origin
852
+
853
+ ## Tagging ##
854
+
855
+ 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.
856
+
857
+ ### Listing Your Tags ###
858
+
859
+ Listing the available tags in Git is straightforward. Just type `git tag`:
860
+
861
+ $ git tag
862
+ v0.1
863
+ v1.3
864
+
865
+ This command lists the tags in alphabetical order; the order in which they appear has no real importance.
866
+
867
+ 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:
868
+
869
+ $ git tag -l 'v1.4.2.*'
870
+ v1.4.2.1
871
+ v1.4.2.2
872
+ v1.4.2.3
873
+ v1.4.2.4
874
+
875
+ ### Creating Tags ###
876
+
877
+ 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.
878
+
879
+ ### Annotated Tags ###
880
+
881
+ Creating an annotated tag in Git is simple. The easiest way is to specify `-a` when you run the `tag` command:
882
+
883
+ $ git tag -a v1.4 -m 'my version 1.4'
884
+ $ git tag
885
+ v0.1
886
+ v1.3
887
+ v1.4
888
+
889
+ 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.
890
+
891
+ You can see the tag data along with the commit that was tagged by using the `git show` command:
892
+
893
+ $ git show v1.4
894
+ tag v1.4
895
+ Tagger: Scott Chacon <schacon@gee-mail.com>
896
+ Date: Mon Feb 9 14:45:11 2009 -0800
897
+
898
+ my version 1.4
899
+ commit 15027957951b64cf874c3557a0f3547bd83b3ff6
900
+ Merge: 4a447f7... a6b4c97...
901
+ Author: Scott Chacon <schacon@gee-mail.com>
902
+ Date: Sun Feb 8 19:02:46 2009 -0800
903
+
904
+ Merge branch 'experiment'
905
+
906
+ That shows the tagger information, the date the commit was tagged, and the annotation message before showing the commit information.
907
+
908
+ ### Signed Tags ###
909
+
910
+ 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`:
911
+
912
+ $ git tag -s v1.5 -m 'my signed 1.5 tag'
913
+ You need a passphrase to unlock the secret key for
914
+ user: "Scott Chacon <schacon@gee-mail.com>"
915
+ 1024-bit DSA key, ID F721C45A, created 2009-02-09
916
+
917
+ If you run `git show` on that tag, you can see your GPG signature attached to it:
918
+
919
+ $ git show v1.5
920
+ tag v1.5
921
+ Tagger: Scott Chacon <schacon@gee-mail.com>
922
+ Date: Mon Feb 9 15:22:20 2009 -0800
923
+
924
+ my signed 1.5 tag
925
+ -----BEGIN PGP SIGNATURE-----
926
+ Version: GnuPG v1.4.8 (Darwin)
927
+
928
+ iEYEABECAAYFAkmQurIACgkQON3DxfchxFr5cACeIMN+ZxLKggJQf0QYiQBwgySN
929
+ Ki0An2JeAVUCAiJ7Ox6ZEtK+NvZAj82/
930
+ =WryJ
931
+ -----END PGP SIGNATURE-----
932
+ commit 15027957951b64cf874c3557a0f3547bd83b3ff6
933
+ Merge: 4a447f7... a6b4c97...
934
+ Author: Scott Chacon <schacon@gee-mail.com>
935
+ Date: Sun Feb 8 19:02:46 2009 -0800
936
+
937
+ Merge branch 'experiment'
938
+
939
+ A bit later, you’ll learn how to verify signed tags.
940
+
941
+ ### Lightweight Tags ###
942
+
943
+ 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:
944
+
945
+ $ git tag v1.4-lw
946
+ $ git tag
947
+ v0.1
948
+ v1.3
949
+ v1.4
950
+ v1.4-lw
951
+ v1.5
952
+
953
+ This time, if you run `git show` on the tag, you don’t see the extra tag information. The command just shows the commit:
954
+
955
+ $ git show v1.4-lw
956
+ commit 15027957951b64cf874c3557a0f3547bd83b3ff6
957
+ Merge: 4a447f7... a6b4c97...
958
+ Author: Scott Chacon <schacon@gee-mail.com>
959
+ Date: Sun Feb 8 19:02:46 2009 -0800
960
+
961
+ Merge branch 'experiment'
962
+
963
+ ### Verifying Tags ###
964
+
965
+ 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:
966
+
967
+ $ git tag -v v1.4.2.1
968
+ object 883653babd8ee7ea23e6a5c392bb739348b1eb61
969
+ type commit
970
+ tag v1.4.2.1
971
+ tagger Junio C Hamano <junkio@cox.net> 1158138501 -0700
972
+
973
+ GIT 1.4.2.1
974
+
975
+ Minor fixes since 1.4.2, including git-mv and git-http with alternates.
976
+ gpg: Signature made Wed Sep 13 02:08:25 2006 PDT using DSA key ID F3119B9A
977
+ gpg: Good signature from "Junio C Hamano <junkio@cox.net>"
978
+ gpg: aka "[jpeg image of size 1513]"
979
+ Primary key fingerprint: 3565 2A26 2040 E066 C9A7 4A7D C0C6 D9A4 F311 9B9A
980
+
981
+ If you don’t have the signer’s public key, you get something like this instead:
982
+
983
+ gpg: Signature made Wed Sep 13 02:08:25 2006 PDT using DSA key ID F3119B9A
984
+ gpg: Can't check signature: public key not found
985
+ error: could not verify the tag 'v1.4.2.1'
986
+
987
+ ### Tagging Later ###
988
+
989
+ You can also tag commits after you’ve moved past them. Suppose your commit history looks like this:
990
+
991
+ $ git log --pretty=oneline
992
+ 15027957951b64cf874c3557a0f3547bd83b3ff6 Merge branch 'experiment'
993
+ a6b4c97498bd301d84096da251c98a07c7723e65 beginning write support
994
+ 0d52aaab4479697da7686c15f77a3d64d9165190 one more thing
995
+ 6d52a271eda8725415634dd79daabbc4d9b6008e Merge branch 'experiment'
996
+ 0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc added a commit function
997
+ 4682c3261057305bdd616e23b64b0857d832627b added a todo file
998
+ 166ae0c4d3f420721acbb115cc33848dfcc2121a started write support
999
+ 9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
1000
+ 964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo
1001
+ 8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
1002
+
1003
+ 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:
1004
+
1005
+ $ git tag -a v1.2 9fceb02
1006
+
1007
+ You can see that you’ve tagged the commit:
1008
+
1009
+ $ git tag
1010
+ v0.1
1011
+ v1.2
1012
+ v1.3
1013
+ v1.4
1014
+ v1.4-lw
1015
+ v1.5
1016
+
1017
+ $ git show v1.2
1018
+ tag v1.2
1019
+ Tagger: Scott Chacon <schacon@gee-mail.com>
1020
+ Date: Mon Feb 9 15:32:16 2009 -0800
1021
+
1022
+ version 1.2
1023
+ commit 9fceb02d0ae598e95dc970b74767f19372d61af8
1024
+ Author: Magnus Chacon <mchacon@gee-mail.com>
1025
+ Date: Sun Apr 27 20:43:35 2008 -0700
1026
+
1027
+ updated rakefile
1028
+ ...
1029
+
1030
+ ### Sharing Tags ###
1031
+
1032
+ 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]`.
1033
+
1034
+ $ git push origin v1.5
1035
+ Counting objects: 50, done.
1036
+ Compressing objects: 100% (38/38), done.
1037
+ Writing objects: 100% (44/44), 4.56 KiB, done.
1038
+ Total 44 (delta 18), reused 8 (delta 1)
1039
+ To git@github.com:schacon/simplegit.git
1040
+ * [new tag] v1.5 -> v1.5
1041
+
1042
+ 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.
1043
+
1044
+ $ git push origin --tags
1045
+ Counting objects: 50, done.
1046
+ Compressing objects: 100% (38/38), done.
1047
+ Writing objects: 100% (44/44), 4.56 KiB, done.
1048
+ Total 44 (delta 18), reused 8 (delta 1)
1049
+ To git@github.com:schacon/simplegit.git
1050
+ * [new tag] v0.1 -> v0.1
1051
+ * [new tag] v1.2 -> v1.2
1052
+ * [new tag] v1.4 -> v1.4
1053
+ * [new tag] v1.4-lw -> v1.4-lw
1054
+ * [new tag] v1.5 -> v1.5
1055
+
1056
+ Now, when someone else clones or pulls from your repository, they will get all your tags as well.
1057
+
1058
+ ## Tips and Tricks ##
1059
+
1060
+ 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.
1061
+
1062
+ ### Auto-Completion ###
1063
+
1064
+ If you use the Bash shell, Git comes with a nice auto-completion script you can enable. Download the Git source code, and look in the `contrib/completion` directory; there should be a file called `git-completion.bash`. Copy this file to your home directory, and add this to your `.bashrc` file:
1065
+
1066
+ source ~/.git-completion.bash
1067
+
1068
+ 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.
1069
+
1070
+ If you’re using Windows with Git Bash, which is the default when installing Git on Windows with msysGit, auto-completion should be preconfigured.
1071
+
1072
+ Press the Tab key when you’re writing a Git command, and it should return a set of suggestions for you to pick from:
1073
+
1074
+ $ git co<tab><tab>
1075
+ commit config
1076
+
1077
+ In this case, typing git co and then pressing the Tab key twice suggests commit and config. Adding `m<tab>` completes `git commit` automatically.
1078
+
1079
+ 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:
1080
+
1081
+ $ git log --s<tab>
1082
+ --shortstat --since= --src-prefix= --stat --summary
1083
+
1084
+ That’s a pretty nice trick and may save you some time and documentation reading.
1085
+
1086
+ ### Git Aliases ###
1087
+
1088
+ 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:
1089
+
1090
+ $ git config --global alias.co checkout
1091
+ $ git config --global alias.br branch
1092
+ $ git config --global alias.ci commit
1093
+ $ git config --global alias.st status
1094
+
1095
+ 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.
1096
+
1097
+ 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:
1098
+
1099
+ $ git config --global alias.unstage 'reset HEAD --'
1100
+
1101
+ This makes the following two commands equivalent:
1102
+
1103
+ $ git unstage fileA
1104
+ $ git reset HEAD fileA
1105
+
1106
+ This seems a bit clearer. It’s also common to add a `last` command, like this:
1107
+
1108
+ $ git config --global alias.last 'log -1 HEAD'
1109
+
1110
+ This way, you can see the last commit easily:
1111
+
1112
+ $ git last
1113
+ commit 66938dae3329c7aebe598c2246a8e6af90d04646
1114
+ Author: Josh Goebel <dreamer3@example.com>
1115
+ Date: Tue Aug 26 19:48:51 2008 +0800
1116
+
1117
+ test for current head
1118
+
1119
+ Signed-off-by: Scott Chacon <schacon@example.com>
1120
+
1121
+ As you can tell, Git simply replaces the new command with whatever you alias it for. 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`:
1122
+
1123
+ $ git config --global alias.visual '!gitk'
1124
+
1125
+ ## Summary ##
1126
+
1127
+ 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.