å¨è§£å³git mergeçå²çªæ¶ï¼ææ¶ææ»å¿ä¸ä½å槽gitå®å¨å¤ªä¸æºè½äºï¼ææä»
ä»
æ¯å¾ä»£ç éé¢æå
¥å è¡ï¼æ²¡æ³å°å并就失败äºï¼åªè½æå·¥å»ä¸ä¸ªä¸ªç¡®è®¤ãçä¸ç¥égitçå并å²çªæ¯æä¹å¤å®çã
å¨ä¸æ¬¡è§£å³äºæ¶åå å个æ件çå并å²çªåï¼æ´æ´è±äºæä¸ä¸ªæä¸åä¸ä¸ªæ©ä¸çæ¶é´ï¼ï¼ï¼æç»äºä¸å®å³å¿ï¼å»çä¸ä¸git
merge代ç éé¢å²çªå¤å®çå
·ä½å®ç°ãæ£æè°å¤æ头åºæ主ï¼è³å°ä¸æ¬¡éå°åæ ·çé®é¢æ¶å°±å¯ä»¥ç¥éèªå·±æ ½å¨è°çæéäºãäºæ¯å°±æäºè¿æ ·ä¸ç¯æç« ï¼è®²è®²
git mergeå
é¨çå²çªå¤å®æºå¶ã
recursive three-way mergeåancestor
gitçæºç
å
ç¨mergeä½å
³é®åæç´¢ï¼ççæ¶åçç¸å
³ä»£ç ã
æ¾äºä¸æ®µæ¶é´ï¼æ¾å°äºgit mergeçæ¶åï¼æ¯è¾å¾
å并æ件çå½æ°å
¥å£ï¼ll_mergeãå¦å¤è¿æä¸ä»½ææ¡£ï¼å®ä¹æåºll_mergeæ£æ¯å并å®ç°çå
¥å£ã
ä»å½æ°ç¾åå¯ä»¥çå°ï¼mmfile_tåºè¯¥å°±ä»£è¡¨äºå¾
å并çæ件ãæ趣çæ¯ï¼è¿éå¾
å并çæ件并ä¸æ¯ä¸¤ä»½ï¼èæ¯ä¸ä»½ã
int ll_merge(mmbuffer_t *result_buf,
const char *path,
mmfile_t *ancestor, const char *ancestor_label,
mmfile_t *ours, const char *our_label,
mmfile_t *theirs, const char *their_label,
const struct ll_merge_options *opts)
çè¿git help mergeç读è
åºè¯¥ç¥éï¼ours表示å½ååæ¯ï¼theirs表示å¾
å并åæ¯ãçå¾åºæ¥ï¼è¿ä¸ªå½æ°å°±æ¯ææ个æ件å¨ä¸ååæ¯ä¸ççæ¬å并å¨ä¸èµ·ãé£ä¹ancestoråæ¯ä½äºåªä¸ªåæ¯å¢ï¼åè¿æ¥ä»è°ç¨æ¹å¼å§é
读代ç ï¼å¯ä»¥çåºå¤§ä½çæµç¨æ¯è¿æ ·çï¼git mergeä¼æ¾åºä¸ä¸ªcommitï¼ç¶å对æ¯ä¸ªå¾
å并çæ件è°ç¨ll_mergeï¼çææç»çå并ç»æãæ注éç说æ³ï¼ancestoræ¯åé¢ä¸¤ä¸ªcommitï¼oursåtheirsï¼çå
Œ
񇝆
ï¼ancestorï¼ãå¦å¤åé¢æå°çææ¡£ä¹è¯´æï¼gitå并çæ¶å使ç¨çæ¯recursive three-way mergeã
å
³äºrecursive three-way mergeï¼ wikipediaä¸æ个ç¸å
³çä»ç»#Recursive_three-
way_merge)ãå°±æ¯å¨å并çæ¶åï¼å°oursï¼theirsåancestorä¸ä¸ªçæ¬çæ件è¿è¡æ¯è¾ï¼è·åoursåancestorç
diffï¼ä»¥åtheirsåancestorçdiffï¼è¿æ ·åè½å¤åç°ä¸¤ä¸ªä¸åçåæ¯å°åºåäºåªäºæ¹å¨ãæ¯ç«åé¢gitéè¦å¤å®å²çªçå
容ï¼å¦æ没æ
ååçæ¬çä¿¡æ¯ï¼åªæ¯ç®åå°æ¯è¾ä¸¤ä¸ªæ件ï¼æ¯åä¸å°çã
é´äºæçç®æ æ¯åægitå¤å®å²çªçæºå¶ï¼æ以没æå»çgitéé¢æ¥æ¾ancestorçå®ç°ãä¸è¿åªéèç¼å¨å¾å½¢åçé¢éç
ä¸ä¸ç¼ï¼å°±å¯ä»¥æ¾å°ancestor commitãï¼æ¯å¦å¨gitlabçnetworkçé¢ä¸ï¼å溯两个åæ¯çcommit线ï¼ä¸ç´å°å²è·¯å£ï¼
æä¸ç¹éè¦æ³¨æçæ¯ï¼revertä¸ä¸ªcommitä¸ä¼æ¹åå®çancestorãæè°çrevertï¼åªæ¯å¨å½åcommitçä¸é¢æ·»å äºæ°ç
undo
commitï¼å¹¶æ²¡ææ¹åâå²è·¯å£âçä½ç½®ãä¸è¦æ³å½ç¶å°è®¤ä¸ºï¼revertä¹åancestorå°±åæä¸ä¸ä¸ªcommitçancestoräºãå°¤å
¶æ¯
å¨revert merge commitçæ¶åï¼æ»æ¯å®¹æå¿æè¿ä¸ªäºå®ãåå¦ä½ revertäºä¸ä¸ªmerge
commitï¼å¨éæ°mergeçæ¶åï¼gitæåç
§çancestorå°ä¸æ¯mergeä¹åçancestorï¼èæ¯revertä¹åç
ancestorãäºæ¯å°±æå°åéå»äºã建议ææ读è
é½çä¸ä¸gitå®æ¹å¯¹äºrevert merge commitæ½å¨åæç说æ³ï¼
https://github.com/git/git/blob/master/Documentation/howto/revert-a-faulty-merge.txt ç»è®ºæ¯ï¼å¦æä¸ä¸ªmerge commitå¼å
¥çbug容æä¿®å¤ï¼è¯·ä¸è¦è½»ærevertä¸ä¸ªmerge commitã
åæxdiff
ä»ll_mergeå¾ä¸è¿½ï¼å¯ä»¥çå°åé¢åºäºä¸æ¡æè·¯ï¼ll_binary_mergeãè¿ä¸ªå½æ°ä¸é¨å¤çbinç±»åæ件çå并ãå®çå®ç°ç®åç²æ´ï¼å¦æä½ æ²¡ææå®å并çç¥ï¼therisæoursï¼ï¼ç´æ¥æ¥Cannot merge binary filesé误ãçæ¥å¨gitçæ¥ï¼äºè¿å¶æ件并没ædiffçä»·å¼ã
主路å¾ä»ll_xdl_mergeå°xdl_mergeï¼è¿å°ä¸ä¸ªå«xdiffçåºä¸ãç»äºæ¾å°git mergeçå
·ä½å®ç°äºã
å¹³å¿è论ï¼xdiffç代ç é£æ ¼ååç³ç³ï¼ä¸ä»
注é太å°ï¼èä¸ç»æä½æååéå±
ç¶ä½¿ç¨ç±»ä¼¼i1ãi2è¿æ ·çå½åï¼çå¾æ头æèèãå¿ç¦æç¥ã
å槽ç»æï¼å
讲ä¸xdl_mergeçæµç¨ãxdl_mergeåäºä¸é¢å件äºï¼
ç±xdl_do_diffå®ætwo-way diffï¼oursåancestorï¼theirsåancestorï¼,çæä¿®æ¹è®°å½ï¼åå¨å°xdfenv_tä¸ã
xdl_change_compactå缩ç¸é»çä¿®æ¹è®°å½ï¼åç¨xdl_build_script建ç«xdchange_té¾è¡¨ï¼è®°å½åæ¹ä¿®æ¹ãxdchange_t主è¦å
æ¬äºä¿®æ¹çèµ·å§è¡å·åä¿®æ¹èå´ã
è¿æ¶ååä¸ç§æ
åµï¼å
¶ä¸ä¸¤ç§æ¯åªæä¸æ¹æä¿®æ¹ï¼åªæoursætheirsä¸æ¡é¾è¡¨ï¼ï¼ç´æ¥éåºãæåä¸ç§æ¯åæ¹é½æä¿®æ¹ï¼éè¦å并修æ¹è®°
å½ãç±äºä¿®æ¹è®°å½æ¯æè¡å·æåºæåçï¼æ以ç´æ¥å并两个é¾è¡¨ãä¿®æ¹è®°å½å¦æ没æéå é¨åï¼æå
å顺åºæ 记为ææ¹ä¿®æ¹/ä»æ¹ä¿®æ¹ãå¦æåçäºéå ï¼å°±è¡¨ç¤ºå
çäºå²çªãä¹åä¼éæ°è¿ä¸é两个å¾
å并é¾è¡¨ï¼å¯¹äºé£äºæ 记为å²çªçé¨åï¼æ¯è¾å®ä»¬æ¯å¦ç¸ççï¼å¦ææ¯ï¼æ 记为åæ¹ä¿®æ¹ã
ç±xdl_fill_merge_bufferè¾åºå并ç»æãå¦ææå²çªï¼è°ç¨fill_conflict_hunkè¾åºå²çªæ
åµãå¦æ没æå²çªï¼æ 记为ææ¹ä¿®æ¹/ä»æ¹ä¿®æ¹/åæ¹ä¿®æ¹ï¼ï¼åå并ancestorçåå
容åä¿®æ¹è®°å½ï¼ææ è®°çç±»ååä¿®æ¹åçå
容ï¼å¹¶è¾åºã
è¾åºå²çªæ
åµç代ç ä½äºfill_conflict_hunkä¸ãå®çå®ç°å¾ç®åï¼æ¯ç«æ¤æ¶æ们已ç»æäºåæ¹ä¿®æ¹çå
容ï¼ç°å¨åªéè¦åæ¶è¾åºå²çªå
容ï¼ä¾ç¨æ·åèãï¼è¿ä¾¿æ¯é£æ¬¡è±äºä¸ä¸ªæä¸åä¸ä¸ªæ©ä¸æ¹æçå²çªçæºå¤´ï¼å¶æå°±æ¯ä½ ï¼å¼ï¼ã
è¾åºæ ¼å¼ææ大家é½å¾çæã该å½æ°ä¼å
æå°è¥å¹²ä¸ª<ï¼ä¸ªæ°ç±DEFAULT_CONFLICT_MARKER_SIZEå³å®ï¼ä¹å³æ¯7个ãç¶åæ¯oursåæ¯åãæ¥çè¾åºææ¹çä¿®æ¹ï¼ç¶åè¾åºè¥å¹²ä¸ª=ãæåæ¯ä»æ¹çä¿®æ¹ï¼ä»¥åè¥å¹²ä¸ª>ãè¿ä¸ªå°±æ¯æ磨人çå并å²çªäºï¼
<<<<<<< HEAD
3
=======
2
>>>>>>> branch1
æ»ç»
git mergeçå²çªå¤å®æºå¶å¦ä¸ï¼å
寻æ¾ä¸¤ä¸ªcommitçå
Œ
񇝆
ï¼æ¯è¾åä¸ä¸ªæ件åå«å¨oursåtheirsä¸å¯¹äºå
Œ
񇝆
çå·®å¼ï¼ç¶åå并è¿ä¸¤ç»å·®å¼ãå¦æåæ¹åæ¶ä¿®æ¹äºä¸å¤å°æ¹ä¸ä¿®æ¹å
容ä¸åï¼å°±å¤å®ä¸ºå并å²çªï¼ä¾æ¬¡è¾åºåæ¹ä¿®æ¹çå
容ã