gitÖÐÔõÑù×÷·Ï commit ²Ù×÷
ÔÚʹÓà git ¾ÙÐа汾¿ØÖÆʱ£¬commit ²Ù×÷ÊDZز»¿ÉÉÙµÄÒ»²½£¬ËüÌåÏÖ½«Ä¿½ñ´úÂë¸ü¸ÄÉúÑĵ½ÍâµØ¿ÍÕ»ÖС£È»¶ø£¬ÔÚÏÖʵʹÓÃÀú³ÌÖУ¬ÎÒÃÇÓÐʱ»áÓöµ½Ò»Ð©ÎÊÌ⣬ÐèÒª×÷·Ï commit ²Ù×÷¡£±¾ÎĽ«»áÏÈÈÝÔõÑù×÷·Ï commit ²Ù×÷¡£
×÷·Ï add ²Ù×÷
ÔÚ git commit ֮ǰ£¬ÎÒÃÇÐèҪʹÓà git add ÏÂÁ¸Ä¶¯Ìí¼Óµ½ staging ÇøÓò£¬×¼±¸Ìá½»¡£ÈôÊÇÎÒÃÇÔÚÖ´ÐÐ git add ÏÂÁîºó£¬ÓÖ·¢Ã÷Ð޸Ĺýʧ£¬²»Ï뽫´ËÐÞ¸ÄÌá½»µ½ staging ÇøÓò£¬¿ÉÒÔͨ¹ýÖ´ÐÐ git reset HEAD ÏÂÁîÀ´×÷·Ï add ²Ù×÷¡£ÕâÌõÏÂÁî»á½«Ö¸¶¨µÄÎļþ»òĿ¼´Ó staging ÇøÓòÖÐÒƳý£¬µ«±£´æÆäÔÚÊÂÇéĿ¼ÖеÄÐ޸ġ£
ÀýÈ磬ÎÒÃÇÖ´ÐÐÁËÈçÏÂÏÂÁîÌí¼ÓÁËÒ»¸öÎļþµ½ staging ÇøÓò£º
git add index.html
µÇ¼ºó¸´ÖÆ
ÏÖÔÚÎÒÃDz»Ï뽫´ËÎļþÌá½»£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî×÷·Ï add ²Ù×÷£º
git reset HEAD index.html
µÇ¼ºó¸´ÖÆ
×÷·Ï commit ²Ù×÷
ÈôÊÇÎÒÃÇÒѾִÐÐÁË commit ²Ù×÷£¬µ«Øʺó·¢Ã÷Ìá½»ÐÅÏ¢Óйýʧ¡¢»òÕßÌá½»µÄÄÚÈÝÓÐÎó£¬ÐèÒªÖØÐÂÐÞ¸ÄÖ®ºóÔÙ´ÎÌá½»£¬ÕâʱÎÒÃǾÍÐèÒª×÷·ÏÉÏÒ»´Î commit ²Ù×÷¡£
ÔÚ git ÖУ¬Ö´ÐÐ×÷·Ï commit ²Ù×÷Ò»Ñùƽ³£ÓÐÁ½ÖÖÒªÁ죺ʹÓà git revert ÏÂÁî»òʹÓà git reset ÏÂÁî¡£
ʹÓà git revert ÏÂÁî
git revert ÏÂÁîÓÃÀ´×÷·Ïij´ÎÌá½»£¬Ëü²»»á¸Ä±äÌá½»ÀúÊ·£¬¶øÊǽ¨ÉèÒ»¸öеÄÌá½»À´×÷·Ï֮ǰµÄÌá½»¡£ÕâÖÖ·½·¨ÊʺÏÓÚÒѾ½«´úÂëÍÆËÍÖÁ¹«¹²¿ÍÕ»ÖеÄÇéÐÎÏÂʹÓá£
Ö´ÐÐÒÔÏÂÏÂÁîÀ´×÷·Ïij¸öÌá½»£º
git revert <commit-id></commit-id>
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬commit-id ÌåÏÖÐèÒª±»×÷·ÏµÄÄÇ´ÎÌá½»µÄ ID ºÅ¡£ÀýÈ磬ÎÒÃÇÒª×÷·Ï×îºóÒ»´ÎÌá½»£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
git revert HEAD
µÇ¼ºó¸´ÖÆ
Ö´ÐдËÏÂÁîºó£¬git »á·¿ªÒ»¸öÎı¾±à¼Æ÷£¬ÈÃÄã±à¼Ìá½»ÐÅÏ¢£¬²¢È·ÈÏ×÷·Ï²Ù×÷¡£
ÈôÊÇÒª×÷·Ï¶à¸öÌá½»£¬¿ÉÒÔÖ¸¶¨¶à¸ö commit-id £¬ÀýÈ磺
git revert <commit-id1> <commit-id2> <commit-id3></commit-id3></commit-id2></commit-id1>
µÇ¼ºó¸´ÖÆ
ʹÓà git reset ÏÂÁî
git reset ÏÂÁîÒ²¿ÉÒÔÓÃÀ´×÷·Ï commit ²Ù×÷£¬²»¹ýËü»á¸Ä±äÌá½»ÀúÊ·£¬Òò´ËÖ»ÊÊÓÃÓÚÍâµØ¿ÍÕ»ÖеIJÙ×÷£¬²»¿ÉÓÃÓÚÒѾÍÆËÍÖÁÔ¶³Ì¿ÍÕ»µÄ²Ù×÷¡£
Ö´ÐÐÒÔÏÂÏÂÁîÀ´×÷·Ïij¸öÌá½»£º
git reset <commit-id></commit-id>
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬commit-id ÌåÏÖÐèÒª±»×÷·ÏµÄÄÇ´ÎÌá½»µÄ ID ºÅ¡£ÀýÈ磬ÎÒÃÇÒª×÷·Ï×îºóÒ»´ÎÌá½»£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
git reset HEAD~1
µÇ¼ºó¸´ÖÆ
Ö´ÐдËÏÂÁîºó£¬×îÐÂÒ»´ÎÌá½»»á±»ÒƳý£¬²¢½«ÆäÐÞ¸ÄÄÚÈݱ£±£´æÊÂÇéĿ¼ÖС£ÐèҪעÖصÄÊÇ£¬ÕâÖÖ·½·¨Ö»Êǽ« commit ²Ù×÷×÷·ÏÁË£¬¶ÔÓ¦µÄ´úÂë¸ü¸Ä²¢Î´±»É¾³ý¡£ÈôÊÇÄãÐèÒª½«´úÂë»Ø¹öµ½Ä³¸öÏêϸ°æ±¾£¬¿ÉÒÔʹÓà git checkout ÏÂÁî¡£
×ܽá
±¾ÎÄÏÈÈÝÁËÔõÑù×÷·Ï Git ÖÐµÄ commit ²Ù×÷£¬°üÀ¨×÷·Ï add ²Ù×÷¡¢Ê¹Óà git revert ºÍ git reset ÏÂÁîÀ´×÷·Ï commit ²Ù×÷¡£ÐèҪƾ֤ÏÖÕæÏàÐÎÑ¡ÔñºÏÊʵÄÒªÁ죬ȷ±£´úÂë°æ±¾¿ØÖÆÎÞÎó¡£
ÒÔÉϾÍÊÇgitÖÐÔõÑù×÷·Ï commit ²Ù×÷µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡