ÁÄÁÄgitÉÑþ³ØýÌí¼ÓÎļþµÄÒªÁì
ÔÚʹÓÃgitÖÎÀíÏîĿʱ£¬ÎÒÃÇÐèÒªÒ»Ö±µÄÌí¼ÓÎļþºÍÎļþ¼Ðµ½°æ±¾¿âÖУ¬¾ÙÐа汾¿ØÖƺÍÐ×÷¿ª·¢¡£¿ÉÊÇ£¬ÓÐʱ¼äÎÒÃÇ¿ÉÄÜÌí¼ÓÁ˹ýʧµÄÎļþ»òÕß²»ÐèÒªµÄÎļþ£¬Õâ¸öʱ¼ä¾ÍÐèÒª½«Æä´Ó°æ±¾¿âÖÐɾ³ý¡£±¾ÎĽ«ÏêϸÏÈÈÝgitɾ³ýÌí¼ÓµÄÎļþµÄÒªÁì¡£
Éó²égit״̬
ÔÚɾ³ýÎļþ֮ǰ£¬ÎÒÃÇÐèÒªÏÈÉó²égit״̬£¬È·¶¨ÐèҪɾ³ýµÄÎļþÊÇ·ñÒѾÌá½»µ½°æ±¾¿âÖС£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÉó²égit״̬£º
$ git status
µÇ¼ºó¸´ÖÆ
ÈôÊÇgit״̬ÖаüÀ¨ÐèҪɾ³ýµÄÎļþ£¬ÄÇô¿ÉÒÔ¼ÌÐø¾ÙÐкóÐøµÄɾ³ý²Ù×÷¡£
ɾ³ýµ¥¸öÎļþ
ÈôÊÇÐèҪɾ³ýµ¥¸öÎļþ£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
$ git rm [file]
µÇ¼ºó¸´ÖÆ
ÆäÖÐ[file]ÌåÏÖÐèҪɾ³ýµÄÎļþÃû¡£Ö´ÐиÃÏÂÁîºó£¬git»á½«Îļþ´Ó°æ±¾¿âÖÐɾ³ý£¬²¢½«É¾³ý²Ù×÷Ìí¼Óµ½ÔÝ´æÇø¡£´Ëʱ£¬ÐèҪʹÓÃÒÔÏÂÏÂÁÐÞ¸ÄÌá½»µ½°æ±¾¿â£º
$ git commit -m "delete file"
µÇ¼ºó¸´ÖÆ
×¢ÖØ£¬ÈôÊÇÐèÒª×÷·Ïɾ³ý²Ù×÷£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
$ git restore [file]
µÇ¼ºó¸´ÖÆ
ÆäÖÐ[file]ÌåÏÖÐèÒª»Ö¸´µÄÎļþÃû¡£
ɾ³ýÎļþ¼Ð
ÈôÊÇÐèҪɾ³ýÕû¸öÎļþ¼Ð£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
$ git rm -r [folder]
µÇ¼ºó¸´ÖÆ
ÆäÖÐ[folder]ÌåÏÖÐèҪɾ³ýµÄÎļþ¼ÐÃû¡£Ö´ÐиÃÏÂÁîºó£¬git»á½«Îļþ¼Ð¼°Æä°üÀ¨µÄËùÓÐÎļþ´Ó°æ±¾¿âÖÐɾ³ý£¬²¢½«É¾³ý²Ù×÷Ìí¼Óµ½ÔÝ´æÇø¡£Í¬ÑùÐèҪʹÓÃÒÔÏÂÏÂÁÐÞ¸ÄÌá½»µ½°æ±¾¿â£º
$ git commit -m "delete folder"
µÇ¼ºó¸´ÖÆ
ÈôÊÇÐèÒª×÷·Ïɾ³ýÎļþ¼Ð²Ù×÷£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
$ git restore [folder]
µÇ¼ºó¸´ÖÆ
ÆäÖÐ[folder]ÌåÏÖÐèÒª»Ö¸´µÄÎļþ¼ÐÃû¡£
»Ö¸´ÒѾɾ³ýµÄÎļþ
ÈôÊÇÐèÒª»Ö¸´ÒѾɾ³ýµÄÎļþ£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
$ git checkout [commitID] -- [file]
µÇ¼ºó¸´ÖÆ
ÆäÖÐ[commitID]ÌåÏÖÐèÒª»Ö¸´µÄcommit ID£¬[file]ÌåÏÖÐèÒª»Ö¸´µÄÎļþ¡£Ö´ÐиÃÏÂÁîºó£¬git»á½«Îļþ»Ö¸´µ½Ö¸¶¨µÄcommit ID°æ±¾ÖС£
ɾ´íÇéÐδ¦Öóͷ£
ÔÚʹÓÃgitɾ³ýÎļþµÄÀú³ÌÖУ¬ÓÐЩÇéÐÎÏ¿ÉÄÜ»áɾ³ýÁ˲»Ó¦¸Ãɾ³ýµÄÎļþ»òÎļþ¼Ð£¬Ôì³É²»ÐëÒªµÄËðʧ¡£Õâʱ£¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏÂÒªÁì¾ÙÐд¦Öóͷ££º
ÖØÐÂÌí¼Ó±»ÎóɾµÄÎļþ»òÎļþ¼Ð
»Ö¸´ÒѾɾ³ýµÄcommit ID°æ±¾
ÈôÊÇÊǶÔÒѾÌá½»µÄÎļþ¾ÙÐÐÎóɾ£¬ÄÇôÐèÒªÖ±½Ó»Ö¸´ÒѾÌá½»µÄcommit ID°æ±¾¡£ÈôÊÇÎóɾµÄÎļþ²¢Ã»ÓÐÌá½»µ½°æ±¾¿âÖУ¬¿ÉÒÔͨ¹ýÖØÐÂÌí¼ÓÀ´µ÷½â¡£
×ܽá
gitÊÇÏÖÔÚ×îΪʢÐеİ汾¿ØÖƹ¤¾ßÖ®Ò»£¬Í¨¹ýgit¿ÉÒÔÀû±ãµÄ½«ÎļþºÍÎļþ¼ÐÌí¼Óµ½°æ±¾¿âÖоÙÐа汾¿ØÖƺÍÐ×÷¿ª·¢¡£¿ÉÊÇ£¬ÔÚʹÓÃgitµÄÀú³ÌÖУ¬Ò²ÐèҪעÖØɾ³ý²Ù×÷µÄ¾«×¼ÐÔ£¬×èÖ¹ÎóɾºÍÊý¾ÝËðʧ¡£±¾ÎÄÏÈÈÝÁËgitɾ³ýÌí¼ÓµÄÎļþµÄÒªÁ죬ϣÍû¿ÉÒÔ×ÊÖú¸÷È˸üºÃµØʹÓÃgit¾ÙÐпª·¢ºÍÖÎÀí¡£
ÒÔÉϾÍÊÇÁÄÁÄgitÉÑþ³ØýÌí¼ÓÎļþµÄÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡