ÔõôÉèÖà git ±àÂë
Ëæ׎ü¼¸Äê°æ±¾¿ØÖƹ¤¾ßµÄÆÕ±éÓ¦Óã¬git ÒѾ³ÉΪ¿ª·¢ÕßÃDZز»¿ÉÉٵŤ¾ßÖ®Ò»¡£×÷Ϊһ¿îÓÅÒìµÄ°æ±¾¿ØÖƹ¤¾ß£¬git µÄÆÕ±éÓ¦ÓÃÒ²Ìá¸ßÁ˱à³ÌµÄЧÂʺʹúÂëµÄ¿Éά»¤ÐÔ¡£²»¹ý£¬Ê¹Óà git µÄʱ¼äÒ²¾³£Óöµ½Ò»Ð©ÎÊÌ⣬ÆäÖÐÒ»¸ö³£¼ûµÄÎÊÌâ¾ÍÊDZàÂëÎÊÌâ¡£±¾ÎĽ«ÖصãÏÈÈÝÔõÑùÉèÖà git ±àÂ룬×ÊÖú¸÷È˸üºÃµØʹÓà git¡£
Ò»¡¢Git µÄ±àÂëÎÊÌâ
Git µÄ±àÂëÎÊÌâÖ÷ÒªÌåÏÖÔÚÁ½¸ö·½Ã棺ÎļþÃû±àÂëºÍÎı¾Îļþ±àÂë¡£ÆäÖУ¬ÎļþÃû±àÂëÖ÷ÒªÖ¸µÄÊÇÎļþÃûÖпÉÄÜ°üÀ¨·Ç ASCII Âë×Ö·ûµÄÎÊÌâ¡£ÔÚ Windows ϵͳÏ£¬ÎļþÃûĬÈÏÊǽÓÄÉ GBK ±àÂëµÄ£¬¶øÔÚ Linux ºÍ MacOS ϵͳÏ£¬ÔòÊǽÓÄÉ UTF-8 ±àÂëµÄ¡£µ±ÎÒÃÇÔÚʹÓà Git ¾ÙÐа汾¿ØÖÆʱ£¬ÈôÊÇʹÓÃÁ˲î±ð±àÂëµÄϵͳ»òÕß²î±ð±àÂëµÄÎļþÃû£¬¾Í¿ÉÄ᷺ܻÆðÎļþÃû»ò·¾¶²»¿É±»×¼È·ÆÊÎöµÄÎÊÌâ¡£
Îı¾Îļþ±àÂëÊÇÖ¸Îı¾ÎļþÖÐ×Ö·û±àÂëµÄÎÊÌâ¡£ÔÚ²î±ðµÄ±àÂëÃûÌÃÖУ¬Í¬ÑùµÄ×Ö·û¿ÉÄܻᱻ´æ´¢Îª²î±ðµÄ¶þ½øÖÆÂëÖµ£¬Õâ¾Í¿ÉÄܵ¼ÖÂÔÚ²î±ðµÄϵͳ»òÈí¼þÖÐÎļþ·¿ªÊ±·ºÆðÂÒÂëµÄÇéÐΡ£¶øÔÚ Git ÖУ¬ÈôÊÇÎı¾ÎļþµÄ±àÂëÃûÌÃÓëϵͳÇéÐβ»Æ¥Å䣬ÔòÔÚÉó²é¡¢±à¼µÈ²Ù×÷ʱҲ»á·ºÆðÂÒÂëÎÊÌâ¡£
¶þ¡¢ÉèÖÃÎļþÃû±àÂë
Õë¶ÔÎļþÃû±àÂëÎÊÌ⣬ÎÒÃÇÐèÒªÉèÖà Git µÄ core.quotepath ÉèÖòÎÊý¡£¸Ã²ÎÊýÓÃÓÚ¾öÒéÊÇ·ñ¶ÔÎļþ·¾¶¾ÙÐбàÂë¡£ÔÚ Windows ϵͳÏ£¬¸Ã²ÎÊýµÄĬÈÏÖµÊÇ true£¬¼´Ç¿ÖƶÔÎļþÃû¾ÙÐбàÂë´¦Àí¡£µ«ÔÚ Linux ºÍ MacOS ϵͳÏ£¬¸Ã²ÎÊýµÄĬÈÏÖµÊÇ false£¬¼´²î³ØÎļþÃû¾ÙÐбàÂë´¦Àí¡£Òò´Ë£¬ÈôÊÇÎÒÃÇÔÚ Windows ϵͳºÍ Linux/MacOS ϵͳ֮¼ä¾ÙÐдúÂë¹²Ïíʱ£¬¾ÍÐèҪעÖØÉèÖøòÎÊý¡£
ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´ÉèÖøòÎÊý£º
git config --global core.quotepath false
µÇ¼ºó¸´ÖÆ
ÈôÊÇÐèÒª»Ö¸´Ä¬ÈÏÉèÖã¬Ôò¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
git config --global core.quotepath true
µÇ¼ºó¸´ÖÆ
Èý¡¢ÉèÖÃÎı¾Îļþ±àÂë
ÔÚÉèÖÃÎı¾Îļþ±àÂëʱ£¬ÎÒÃÇÐèҪעÖØÁ½¸ö·½Ã棺ȫ¾ÖÉèÖú͵¥¸öÎļþÉèÖá£
È«¾ÖÉèÖÃ
ÎÒÃÇ¿ÉÒÔͨ¹ýÉèÖà Git µÄ git config ²ÎÊýÀ´ÉèÖÃÈ«¾ÖĬÈϵÄÎı¾Îļþ±àÂë¡£ÔÚ Git ÖУ¬ÓÐÁ½¸öÏà¹Ø²ÎÊý£ºcore.autocrlf ºÍ core.safecrlf¡£
core.autocrlf ²ÎÊýÓÃÓÚ¿ØÖÆ»»ÐзûµÄת»»¡£ÔÚ Windows ϵͳÖУ¬Ä¬ÈϵÄÎı¾Îļþ»»ÐзûΪ CRLF£¬¶øÔÚ Linux ºÍ MacOS ϵͳÖУ¬ÔòΪ LF¡£µ±ÔÚ Git ÖÐÌí¼Ó»òÐÞ¸ÄÎı¾Îļþʱ£¬ÈôÊǸòÎÊýÉèÖÃΪ true£¬Git »á½«ÎļþÖÐµÄ CRLF ת»»Îª LF ²¢´æ´¢£¬¶øÔÚ´Ó Git Öн«Îļþ checkout ³öÀ´Ê±£¬»á½«ÎļþÖÐµÄ LF ת»»Îª CRLF¡£ÈôÊǸòÎÊýÉèÖÃΪ input£¬Ôò»áÇ¿ÖÆʹÓû»Ðзû LF¡£
ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´ÉèÖøòÎÊý£º
git config --global core.autocrlf true
µÇ¼ºó¸´ÖÆ
»òÕߣº
git config --global core.autocrlf input
µÇ¼ºó¸´ÖÆ
core.safecrlf ²ÎÊýÓÃÓÚ¼ì²éÎı¾ÎļþµÄ±àÂëÃûÌᣵ±¸Ã²ÎÊýÉèÖÃΪ true ʱ£¬Git »á¼ì²éÎļþÖеĻ»ÐзûÊÇ·ñ׼ȷ£¬ÈôÊÇÎļþÖеĻ»ÐзûÓÐÎÊÌ⣬Ôò»á×èÖ¹ÎļþµÄÌá½»¡£ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´ÉèÖøòÎÊý£º
git config --global core.safecrlf true
µÇ¼ºó¸´ÖÆ
µ¥¸öÎļþÉèÖÃ
ÈôÊÇÎÒÃÇÐèÒªÕë¶Ôij¸öÎı¾Îļþ¾ÙÐÐÌØÊâµÄ±àÂëÉèÖ㬿ÉÒÔÔÚ¸ÃÎļþËùÔÚµÄ Git ¿ÍÕ»ÖÐÌí¼Ó .gitattributes Îļþ£¬²¢ÔÚ¸ÃÎļþÖоÙÐÐÉèÖá£ÔÚ .gitattributes ÎļþÖУ¬ÎÒÃÇ¿ÉÒÔΪÿ¸öÎļþÖ¸¶¨ÎļþÃûºÍÎļþ·¾¶Ä£Ê½£¬²¢Ö¸¶¨ÏìÓ¦µÄÎı¾ÊôÐԺͱàÂëÃûÌá£ÐèҪעÖصÄÊÇ£¬.gitattributes Îļþ±ØÐèʹÓà UTF-8 ±àÂë¡£
ÀýÈ磬ÒÔÏÂÉèÖÿÉÒÔΪ PHP ÎļþÖ¸¶¨ UTF-8 ±àÂ룺
*.php text encoding=utf-8
µÇ¼ºó¸´ÖÆ
ÐèҪעÖصÄÊÇ£¬ÔÚ¾ÙÐе¥¸öÎļþ±àÂëÉèÖÃʱ£¬ÈôÊÇÒѾ½«¸ÃÎļþ¼ÓÈëµ½ Git ÖУ¬ÔòÐèÒªÏȽ«¸ÃÎļþ´Ó Git ÖÐɾ³ý£¬È»ºóÔÙ¾ÙÐбàÂëÉèÖá£
ËÄ¡¢×ܽá
ͨ¹ýÒÔÉϵÄÏÈÈÝ£¬ÎÒÃÇ¿ÉÒÔ¿´µ½ Git µÄ±àÂëÎÊÌâÒ»·½ÃæÊÇÈ¡¾öÓÚϵͳÇéÐεıàÂëÃûÌã¬ÁíÒ»·½ÃæÔòÊÇÈ¡¾öÓÚÏêϸµÄÎļþ±àÂëÃûÌá£ÎªÁ˸üºÃµØʹÓà Git£¬ÎÒÃÇÐèÒªÏàʶÕâЩ±àÂëÏà¹ØµÄÎÊÌ⣬²¢Æ¾Ö¤ÏÖÕæÏàÐÎÀ´¾ÙÐÐÏìÓ¦µÄÉèÖᣱ¾ÎÄÖ÷ÒªÏÈÈÝÁË Git ±àÂëÎÊÌâµÄ½â¾ö¼Æ»®£¬Ï£Íû¶Ô¶ÁÕßÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇÔõôÉèÖà git ±àÂëµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡