ÔõÑù×÷·Ï git merge ²Ù×÷
git ÊÇÄ¿½ñÒµ½ç×î³£Óõİ汾¿ØÖƹ¤¾ßÖ®Ò»£¬git merge ÊÇ git ÖÐ×î³£¼ûµÄ²Ù×÷Ö®Ò»£¬Ëü¿ÉÒÔ½«Á½¸ö²î±ðµÄ·ÖÖ§ºÏ²¢µ½Ò»Æ𡣿ÉÊÇ£¬ÓÐʱ¼äÎÒÃǺϲ¢ÁËÒ»¸ö²»Ó¦ºÏ²¢µÄ·ÖÖ§»ò´úÂ룬ÔÚÕâÖÖÇéÐÎÏ£¬ÎÒÃÇÐèÒª×÷·ÏºÏ²¢¡£ÄÇô£¬ÔõÑù×÷·Ï git merge ²Ù×÷ÄØ£¿±¾ÎĽ«Îª¸÷ÈËÏÈÈÝһЩ½â¾ö²½·¥¡£
ÔõÑùÉó²éºÏ²¢ÇéÐÎ
ʹÓà git log ÏÂÁî
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÏàʶºÏ²¢µÄÇéÐΡ£ÎÒÃÇ¿ÉÒÔʹÓà git log ÏÂÁîÉó²éÏà¹ØÐÅÏ¢¡£Ö´ÐÐÏÂÁ
git log --graph --oneline --decorate
µÇ¼ºó¸´ÖÆ
¸ÃÏÂÁչʾһ¸öƯÁÁµÄÌá½»ÀúÊ·¿ÉÊÓ»¯Í¼£¬°üÀ¨ËùÓзÖÖ§µÄºÏ²¢ºÍÌá½»ÐÅÏ¢¡£
ʹÓà git reflog ÏÂÁî
Git reflog ÏÂÁî¿ÉÒÔÁгö Git ÒýÓõÄÐÞ¸ÄÀúÊ·£¬°üÀ¨ commit¡¢merge¡¢rebase µÈ¡£Ö´ÐÐÏÂÁ
git reflog
µÇ¼ºó¸´ÖÆ
¸ÃÏÂÁչʾËùÓÐ git ²Ù×÷µÄÀúÊ·¼Í¼£¬°üÀ¨ git merge ²Ù×÷¡£Êä³öÈçÏ£º
cb61cbb HEAD@{0}: merge dev_branch: Fast-forward a44ab51 HEAD@{1}: checkout: moving from dev_branch to master cb61cbb HEAD@{2}: merge dev_branch: Merge made by the 'recursive' strategy. e6c8ed6 HEAD@{3}: checkout: moving from master to dev_branch
µÇ¼ºó¸´ÖÆ
×÷·ÏºÏ²¢
ʹÓà git reset ÏÂÁî
ÈôÊÇÎÒÃÇÏëÒªÍêÈ«×÷·Ï merge ²Ù×÷£¬²¢ÇÒ²»Ï£Íû¶ÔÔÓеÄÌá½»ÀúÊ·Ôì³ÉÓ°Ï죬¿ÉÒÔͨ¹ý git reset ÏÂÁîÀ´ÊµÏÖ¡£Ö´ÐÐÏÂÁ
git reset --hard HEAD^
µÇ¼ºó¸´ÖÆ
ÉÏÊöÏÂÁî»á½« HEAD Ö¸ÕëÏòÍËÈ´Ò»´ÎÌá½»£¬²¢É¾³ý merge ²Ù×÷Ëù±¬·¢µÄËùÓдúÂëת±ä¡£×¢ÖØ£¬ÕâÊÇÒ»ÖÖΣÏÕµÄ×ö·¨£¬Ò»¶¨ÒªÐ¡ÐÄʹÓá£
ʹÓà git revert ÏÂÁî
ÈôÊÇÎÒÃÇÏëÒª±£´æÔÓеÄÌá½»ÀúÊ·£¬²¢ÇÒ×÷·Ïij¸ö merge ²Ù×÷Ëù´øÀ´µÄÓ°Ï죬¿ÉÒÔʹÓà git revert ÏÂÁî¡£Ö´ÐÐÏÂÁ
git revert -m 1 <merge></merge>
µÇ¼ºó¸´ÖÆ
×¢ÖØ£¬ÕâÀïµÄ -m 1 ²ÎÊýÊÇÖ¸½ö×÷·ÏÒ»¸ö¸¸ commit µÄת±ä£¬ÈôÊÇÒ»¸ö merge commit ºÏ²¢Á˶à¸ö¸¸ commit£¬ÎÒÃÇÐèҪʹÓà -m 2¡¢-m 3 µÈ²ÎÊý£¬ÏêϸʹÓÃÄĸö²ÎÊýÐèҪƾ֤ÇéÐζø¶¨¡£
ʹÓà git reset ÏÂÁîºÍ git push ÏÂÁî
ÈôÊÇÒѾ½« merge ²Ù×÷ push µ½ÁËÔ¶³Ì¿ÍÕ»£¬ÎÒÃÇÐèҪʹÓà git reset ÏÂÁÍâµØ¿ÍÕ»»¹Ôµ½ merge ²Ù×÷Ç°µÄ״̬£¬ÔÙʹÓà git push -f ÏÂÁԶ³Ì¿ÍջǿÖÆ»ØÍ˵½ÏàͬµÄ״̬¡£ÕâÀïÐèҪעÖصÄÊÇ£¬ÕâÖÖ×ö·¨»áɾ³ýÔ¶³Ì¿ÍÕ»ÖеÄËùÓÐÐ޸ģ¬²¢ÇÒ¿ÉÄܵ¼ÖÂÆäËûÈ˵ĴúÂë·ºÆðÎÊÌ⣬Òò´ËÐèÒªºÜÊÇСÐÄʹÓá£
×ܽá
±¾ÎÄÏÈÈÝÁËÔõÑù×÷·Ï git merge ²Ù×÷£¬°üÀ¨Í¨¹ý git reset ÏÂÁî¡¢git revert ÏÂÁî¡¢git reset ÏÂÁîºÍ git push ÏÂÁîµÈ·½·¨¡£ÔÚʹÓÃÕâЩÏÂÁîʱ£¬Ò»¶¨ÒªÐ¡ÐÄÉóÉ÷£¬ÒÔ×èÖ¹¶Ô´úÂëÔì³É²»ÐëÒªµÄÓ°Ï졣ͬʱ£¬ÎÒÃÇ»¹ÏàʶÁËÔõÑùÉó²é git merge ²Ù×÷µÄÏà¹ØÐÅÏ¢£¬Õâ¹ØÓÚ½â¾ö git merge Ïà¹ØÎÊÌâºÜÊÇÓÐ×ÊÖú¡£
ÒÔÉϾÍÊÇÔõÑù×÷·Ï git merge ²Ù×÷µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡