ååã«å¼ãç¶ãGitã®ä½¿ãæ¹ãã'ãããã ã¤ãããã'ã¨æ¸ãã¦ãã¾ããããããªã«é«åº¦ãªãã¨ã¯ãã¦ãã¾ããã'ããããã®ãã£ã½'ãããã¯é²ãã 使ãæ¹ã ã¨è§£éãã¦ãã ããã
å·®åãåã
ã§ã¯ãgreet.rbãå¤æ´ãã¦ããã¾ãã'Hi, git!'ã'Hello, git!'ã«å¤æ´ããã¨ãã¾ãã'git status'ã§ã¯modifiedã¨ãªãã¾ãã
å¤æ´ã'.git/index'ã«åæ ããã«ã¯'git add greet.rb'ã¨ãã¾ãã
ããã¸ã§ã¯ãã®HEAD*1ã¨ã®å·®åãåãã«ã¯'git diff'ã使ãã¾ãã
$ git diff --cached diff --git a/greet.rb b/greet.rb index 5f73eff..933f909 100644 --- a/greet.rb +++ b/greet.rb @@ -1,2 +1,2 @@ -puts 'Hi, git!' +puts 'Hello, git!'
'-'ã¯åé¤ããé¨å'+'ã¯è¿½å ããé¨åã¨ãè¦ãã¾ãã¾ã®æå³ã§ãã
ä»åã¯'--cached'ãªãã·ã§ã³ãã¤ãã¦ããã®ã§'.git/inde'ã¨ã®å·®åãåã£ã¦ã¾ããããªãã·ã§ã³ãã¤ããªããã°ã¯ã¼ãã³ã°ãã£ã¬ã¯ããª*2ã¨ã®å·®åãåãã¾ãã
å¤æ´ãã³ããããã¦ããã¾ãããã
$ git commit -a -m 'HiãHelloã«å¤æ´' Created commit 4bc394d: HiãHelloã«å¤æ´ 1 files changed, 1 insertions(+), 1 deletions(-)
ä»åã¯ã³ãããã¡ãã»ã¼ã¸ã«æ¥æ¬èªã使ç¨ãã¦ã¿ã¾ããã
ã³ããããã°ãè¦ã
'git log'ã³ãã³ãã§è¦ããã¨ãã§ãã¾ãã
$ git log (ãã¼ã¸ã£ãèµ·åãã¦) commit 4bc394d85ff2b3cda654b92f42ce2bf93d8ff665 Author: your name <[email protected]> Date: Wed May 14 21:50:40 2008 +0900 HiãHelloã«å¤æ´ commit db58434795394232ddf5ed09416c619647ef21f8 Author: your name <[email protected]> Date: Wed May 14 21:25:51 2008 +0900 initial commit
ä¸ãããSHA1ããã·ã¥å¤*3ãã³ããããã人ãã¿ã¤ã ã¹ã¿ã³ããã³ãããã¡ãã»ã¼ã¸ã¨ãªã£ã¦ãã¾ãã'git log'ã§ã¯'--pretty'ãªãã·ã§ã³ã§æ¸å¼ãç´°ããæå®ã§ããã®ã§ããããããçããããã©ã«ãã§ã¯'--pretty=medium'ãæå®ãããã¨ã«ãªã£ã¦ãã¾ãã'--preytty'ã§æå®ã§ããæ¸å¼ã«ã¤ãã¦ã¯'man git-log'ã§ç¢ºèªãã¦ãã ããã
以åã®ãã¡ã¤ã«ã®ç¶æ ãè¦ã
以åã®ã³ãããæã®ãã¡ã¤ã«ã®ç¶æ ãã¿ãã«ã¯'git show'ã使ãã¾ããã©ã®ã³ãããããæå®ããã«ã¯ã¿ã°ãSHA1ããã·ã¥å¤ãç¨ãã¾ããä»åã¯ã¿ã°ãã¤ãã¦ããªãã®ã§å ã»ã©ã®'git log'ã§å¾ãããSHA1ããã·ã¥å¤ãç¨ãã¾ãããããªã«é·ãã®è¦ããããªãã§ãããã¨ããããã§SHA1ããã·ã¥å¤ã¯çç¥ãã¦ããããã¨ã«ãªã£ã¦ãã¾ããã¤ã¾ã'db58434795394232ddf5ed09416c619647ef21f8'ã¯'db58434'ã§OKã ã¨è¨ãããã§ãã
$ git show db58434:greet.rb (ãã¼ã¸ã£ãèµ·åãã¦) puts 'Hi, git!'
å¤æ´åã®å 容ãå¾ããã¾ããããã¡ã¤ã«ã®æå®ã¯'SHA1ããã·ã¥å¤:ãã¡ã¤ã«ã®ãã¹'ã¨ãã風ã«':'ã§åºåã£ã¦è¡ãã¾ãããã¡ã¤ã«ãæå®ããªãã£ããã':'ã使ããªããã°*4çµæã¯diffå½¢å¼ã§è¡¨ç¤ºããã¾ãã
以åã®ã³ãããããã§ãã¯ã¢ã¦ããã
ã§ã¯ãã¯ã¼ãã³ã°ãã£ã¬ã¯ããªå
ã®å
容ã以åã®ã³ãããæã«æ»ãã«ã¯ã©ãããã°ããã§ãããããçãã¯'git checkout'ãç¨ããæ¹æ³ã§ãã
'git checkout'ã«SHA1ããã·ã¥å¤ãã¿ã°ãæå®ãããã¨ã§ãã®ã³ãããæã®ç¶æ
ãåãåºãã¾ã(ãã§ãã¯ã¢ã¦ã)ããã¡ã¤ã«ãæå®ãããã¨ãå¯è½ã§ãã
$ git checkout db58434 greet.rb $ cat greet.rb puts 'Hi, git!'
æä½ãåãæ¶ã
ããã»ã©æåã®ã³ãããæã®greet.rbããã§ãã¯ã¢ã¦ããã¾ãããããããããæ¢ããããªã£ãå ´åã¯ãã³ãããåã§ããã°ä»¥ä¸ã®æ§ã«ãã¦åãæ¶ããã¨ãã§ãã¾ãã
$ git reset --hard HEAD HEAD is now at 4bc394d HiãHelloã«å¤æ´ $ cat greet.rb puts 'Hello, git!'
ããã³ãããå¾ã§ããã°ï¼ç¨®é¡ã®æ¹æ³ãããã¾ãã
- ä¿®æ£ããããã®ãæ¹ãã¦ã³ããããã
- å±¥æ´ãä¿®æ£ãã¦ãªãã£ããã¨ã«ãã
ããããä¸åº¦å ¬éãã¦ãã¾ã£ãå ´åã¯æ¹ãã¦ã³ãããããªãããªããã°æ··ä¹±ãæãã¾ãããgitã¯å±¥æ´ãå¤æ´ããããã¨ãæ³å®ãã¦ããªãã®ã§ä¸é½åãçãã¦ãã¾ãããäºã¤ç®ã®æ¹æ³ã¯æ¨å¥¨ããã¾ããããã£ã¦ããã§ã¯å²æãã¾ãã
æ¹ãã¦ã³ãããããªããã®ã¯é¢åãªã®ã§ãããããããããã¨ã«gitã«ã¯ããã¯ãã¦ãããæ©è½ãããã¾ãã
$ git revert HEAD
ã¨ãã£ã¿ãéãã¦ã³ãããã¡ãã»ã¼ã¸ã®å ¥åãä¿ããã¾ãããæ¢ã«Revertãããã¨ã示ãã¡ãã»ã¼ã¸ãå ¥åããã¦ããã®ã§ãã®ã¾ã¾ã³ããããããã¨ãåºæ¥ã¾ãã
åã³åå²ãã¾ãã次ã¯ã¿ã°ããã©ã³ãã«ã¤ãã¦ã