git-rerereã®ã¡ã¢
git-rerereã£ã¦ãªããã¬ã¬ã¬ã®ããããã¿ããã§ãã(Reuse recorded resolution of conflicted merges ã ãããª)ãåããããªè¡çªãä½åº¦ãèµ·ããç¶æ³ã§ä½¿ãã¨ã¨ã£ã¦ã便å©ãªããã§ã調ã¹ã¤ã¤ãã¡ã¢ã
Linusãè¨ã£ã¦ãããç¡é§ãªãã¼ã¸ã³ãããããã¦ããå®ç¾ããã«ã¯ãrebaseãããã°ãããããã¨æã£ã¦ããã ãã©ãæ¢ã«å
¬éãã¦ãããããªãã©ã³ãã¨ãªãã¨ãrebaseããããã«ãããã¾ããã
ã§ãéä¸ã§ã¡ãã£ã¨ã ãæ¬ç·ã¨ãã¼ã¸ãã¦ãã¹ããã¦ã¿ãããªã£ããããã¼ã¸ããå¾ã§ããç´ãã¦å度ãã¼ã¸ãã¦ã¿ãããªã£ããããããã¡ã§ãã
ãããªãã¨ãããã®ããåãããã£ã¦ããããªã³ã³ããªã¯ãã®è§£æ¶ãåããããªãã¼ã¸ãç¹°ãè¿ãã¨ãåãããã«è¡çªãã¦ãã¨ãããä½åº¦ãæã§ç´ãä½æ¥ãç¹°ãè¿ããããã¡ã«ãªã£ã¦ãæ³£ãããã«ãªãã¾ãããã¨ãã£ã¦ãã¼ã¸ãéçã¾ã§ææ
¢ãã¦ä¸çºã§FAã¨ããã®ããããããããã§rerereã
è¡çªããç¶æ³
ãããªãã¡ã¤ã«ãããã¨ãã¦ã
<html><body> <h1>test</h1> <div> <p> ããã¬ã¤ã </p> </div> </body></html>
gitã§masterãã©ã³ãã¨ãããããæåããããtopicãã©ã³ããä½ããããããã§å¤æ´ãè¡ãã¾ããã
masterãã©ã³ãï¼ï¼è¡ç®ãå¤æ´ï¼
<html><body> <h1>test</h1> <div id="hello"> <p> ããã¬ã¤ã </p> </div> </body></html>
topicãã©ã³ãï¼ï¼è¡ç®ã¨ï¼è¡ç®ãå¤æ´ï¼
<html><body> <h1>test</h1> <div class="welcome"> <p> ããã«ã¡ã¯ </p> </div> </body></html>
ãããªç¶æ³ã§ãã
$ git show-branch ! [master] divã¿ã°ã«idã追å * [topic] "ããã«ã¡ã¯"ã«å¤æ´ãclass追å -- * [topic] "ããã«ã¡ã¯"ã«å¤æ´ãclass追å + [master] divã¿ã°ã«idã追å +* [topic^] initial
ããããå³ã ã¨ãããªæãã
o---o topic / o---o---o master
ãã®ç¶æ
ã§ãã¼ã¸ãããããï¼è¡ç®ã®divã¿ã°ã®è¡ãã¶ã¤ããããã§ãã
rerereãæå¹ã«ãã¦ãã¼ã¸
topicãã©ã³ãã¯ãã®ææããã¤ãmasterãã©ã³ãã«æ»ããããã ãã©ãæåããããå¾ã«masterãã©ã³ãã®æ¹ãé²åãã¦ããã®ã§ããã®åãåãè¾¼ã¾ãªãã¨ãã¹ããã§ãã¾ããã
åãè¾¼ãéã«ã¯ãåãè¡ãå¤æ´ãã¦ããã®ã§ããã£ã¨ã³ã³ããªã¯ããã¾ãã
ã¨ããããrerereãæå¹ã«ãã¾ãã
å ¨ä½çã«æå¹ã«ããå ´å ~/.gitconfig ã«ä»¥ä¸ã®ããã«è¨å®ãã
[rerere] enabled = true
ã¨ãããããã®ãªãã¸ããªã§æå¹ã«ããå ´å
$ mkdir .git/rr-cache
topicãã©ã³ãã«masterãã©ã³ããé²åããåãåãè¾¼ãã§ãã¹ããããã
ãã¼ã¸
$ git checkout topic Switched to branch 'topic' $ git merge master Auto-merging index.html CONFLICT (content): Merge conflict in index.html Recorded preimage for 'index.html' Automatic merge failed; fix conflicts and then commit the result.
ã³ã³ããªã¯ããããèªåãã¼ã¸å¤±æã
ã§ã Recorded preimage for 'index.html' ã¨ãåºã¦ã¾ããrerereçºåã
$ git status index.html: needs merge # On branch topic # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # unmerged: index.html # no changes added to commit (use "git add" and/or "git commit -a")
äºå®éãã®å±éã
$ git diff diff --cc index.html index b21ded8,3a98e93..0000000 --- a/index.html +++ b/index.html @@@ -1,9 -1,9 +1,13 @@@ <html><body> <h1>test</h1> ++<<<<<<< HEAD + <div class="welcome"> ++======= + <div id="hello"> ++>>>>>>> master <p> - ããã¬ã¤ã + ããã«ã¡ã¯ </p> </div>
ï¼è¡ç®ãããæãã«ä¿®æ£ãã¾ãã
<html><body> <h1>test</h1> <div id="hello" class="welcome"> <p> ããã«ã¡ã¯ </p> </div> </body></html>
masterï¼topicãªæãã®å 容ã
$ git diff diff --cc index.html index b21ded8,3a98e93..0000000 --- a/index.html +++ b/index.html @@@ -1,9 -1,9 +1,9 @@@ <html><body> <h1>test</h1> - <div class="welcome"> - <div id="hello"> ++ <div id="hello" class="welcome"> <p> - ããã¬ã¤ã + ããã«ã¡ã¯ </p> </div>
ã³ããã
$ git add index.html $ git commit Recorded resolution for 'index.html'. [topic 5ad8548] Merge branch 'master' into topic
rerereãè¡çªã®è§£æ¶æ¹æ³ãè¨é²ããããã§ãã
ã¨ãããããã¼ã¸ãæåããã®ã§ãããã§masterãã©ã³ãã®ææ°ï¼topicãã©ã³ãã®ç¶æ ã§ããã¹ããåºæ¥ã¾ãã
ãã¹ããè¯å¥½ãªããå®å¿ãã¦ç¶ããåºæ¥ãã¨ãããã®ã
ãããã°ãè¦ã¦ã¿ãã¨ããã£ãã®ãã¼ã¸ã§ãã¼ã¸ã³ããããåºæ¥ã¦ãã¾ãã
$ git log --oneline 5ad8548 Merge branch 'master' into topic 9e2e252 "ããã«ã¡ã¯"ã«å¤æ´ãclass追å f0631e9 divã¿ã°ã«idã追å 9dceaee initial
ãã®ã¾ã¾ããã¯ãç¶ãã¦ã
bbcd955 ããã¯ç¶ã 5ad8548 Merge branch 'master' into topic 9e2e252 "ããã«ã¡ã¯"ã«å¤æ´ãclass追å f0631e9 divã¿ã°ã«idã追å 9dceaee initial
ãããªé¢¨ã«ç¶ããããã¨ããã®ãã©ã³ããããã¼ã¸ããæã«ããã®ãã¼ã¸ã³ãããããã¾ãã§ä»ãã¦ãã¦ãã¾ãã¾ããï¼ã¤ã ããªãã¾ã ããããã®èª¿åã§ä½åããã¼ã¸ãã¹ããéããã¨ããªã沢山ã®ãã¼ã¸ã³ããããåºæ¥ã¦ãã¾ããLinusãªããã£ããåãè¾¼ãã§ãããªãã¨ãããã¨ã«ã
ãªã®ã§ãããã«ç¶ããããã®ã§ããã°ããã£ãã®ãã¼ã¸ã¯ãã£ããåãæ¶ãã¾ãã
$ git reset --hard HEAD^ HEAD is now at 9e2e252 "ããã«ã¡ã¯"ã«å¤æ´ãclass追å $ git log --oneline 9e2e252 "ããã«ã¡ã¯"ã«å¤æ´ãclass追å 9dceaee initial
ãã¼ã¸ããåã«æ»ãã¾ããã
æ»ã£ãç¶æ ã§ãä½ãç¶ããããã¾ãã
diff --git a/index.html b/index.html index b21ded8..0404d83 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,9 @@ <p> ããã«ã¡ã¯ </p> + <p> + ããããï¼ + </p> </div>
ã³ããããã¦ã¿ã¾ã
$ git commit -a -m 'ãããã 追å ' [topic 23d83ed] ãããã 追å 1 files changed, 3 insertions(+), 0 deletions(-) $ git log --oneline 23d83ed ãããã 追å 9e2e252 "ããã«ã¡ã¯"ã«å¤æ´ãclass追å 9dceaee initial
ã³ãããããã®ã§ãå度masterãã©ã³ãããã¼ã¸ãã¦ãã¹ããããã
$ git merge master Auto-merging index.html CONFLICT (content): Merge conflict in index.html Resolved 'index.html' using previous resolution. Automatic merge failed; fix conflicts and then commit the result.
ãã£ãã¨åãããã«ã³ã³ããªã¯ãããããã©ããã
$ git diff diff --cc index.html index 0404d83,3a98e93..0000000 --- a/index.html +++ b/index.html @@@ -1,12 -1,9 +1,12 @@@ <html><body> <h1>test</h1> - <div class="welcome"> - <div id="hello"> ++ <div id="hello" class="welcome"> <p> - ããã¬ã¤ã + ããã«ã¡ã¯ + </p> + <p> + ããããï¼ </p> </div>
rerereãçºåãã¦ããã£ãã®æåãã¼ã¸ãåç¾ããã¦ããï¼ãrerereæãã¹ãã
ä¸å¿ããã£ã¨diffã確èªããããã³ãããããã ãã
$ git add index.html $ git commit [topic bd9e014] Merge branch 'master' into topic
ããã«ã¾ãç¶ããããããªããresetã§ãã¼ã¸ãåãæ¶ãã¦â¦ä»¥ä¸ç¹°ãè¿ããã¨ããã°ããã¹ãã®ããã®ãã¼ã¸ã³ãããã¯æ®ããªãã§æ¸ãã¨ã
rerereã£ã¦ãã£ãã以åãããã£ãã¿ããã§ããç¥ããªãã£ãã
stashã¿ããã«rerereã®ãªã¹ãè¦ããã¨ãpopã¨ãpushã¨ãapplyã¨ãåºæ¥ãããã£ã¨ä¾¿å©ãªæ°ããããªãã