gitignoreÎļþÆð²»ÁË×÷ÓÃÔõô½â¾ö
gitignore Îļþ²»ÉúЧµÄ½â¾öÒªÁ죺ȷÈÏÎļþÃû׼ȷΪ “.gitignore” ²¢Î»ÓÚ¸ùĿ¼¡£¼ì²éģʽÓï·¨ÊÇ·ñ׼ȷ£¬°üÀ¨Ê¹ÓÃÇ°µ¼Ð±¸Ü¡¢Õýб¸ÜºÍͨÅä·û¡£¸üРgit °æ±¾ÖÁ 1.8 ÒÔÉÏ¡£Ê¹Óà “git rm –cached” ɾ³ýÒÑÌí¼Óµ½ git µÄÎļþ¡£×èÖ¹ÔÚ gitignore ÎļþÖÐʹÓÃÁýÕÖ¸üͨÓùæÔòµÄÌض¨¹æÔò¡£ÔÚ windows ÉÏʹÓÃÕýб¸Ü (/) ºÍ lf »»Ðзû¡£É¨³ýÎļþϵͳȨÏÞ¡¢ÌØÊâ×Ö·û´¦Öóͷ£ºÍ·À²¡¶¾Èí¼þ×ÌÈÅ¡£
gitignore Îļþ²»ÉúЧµÄ½â¾öÒªÁì
gitignore ÎļþÊÇÒ»ÖÖÓÃÓÚºöÂÔÌض¨Îļþ»òĿ¼²»±» Git °æ±¾¿ØÖƸú×ÙµÄÎļþ¡£µ± gitignore Îļþ²»Æð×÷ÓÃʱ£¬¿ÉÄÜÊÇÓÉÓÚÒÔÏÂÔµ¹ÊÔÓÉ£º
1. ÎļþÃû²»×¼È·
gitignore Îļþ±ØÐèÃüÃûΪ “.gitignore”£¬²¢ÇÒλÓÚÏîÄ¿µÄ¸ùĿ¼ÖС£ÈôÊÇÎļþÃû»ò·¾¶²»×¼È·£¬Git ½«ÎÞ·¨Ê¶±ðËü¡£
2. Óï·¨¹ýʧ
gitignore ÎļþÖеÄģʽ×ñÕÕÌض¨µÄÓï·¨¡£ÈôÊÇģʽÖб£´æÓï·¨¹ýʧ£¬Git ½«ÎÞ·¨×¼È·Ú¹ÊÍËü¡£³£¼ûµÄÓï·¨¹ýʧ°üÀ¨£º
- ÒÅÍüÌí¼ÓÇ°µ¼Ð±¸Ü (/)
- ʹÓ÷´Ð±¸Ü (\) ¶ø²»ÊÇб¸Ü (/)
- δʹÓÃͨÅä·û (*) ºÍÎʺŠ(?)
3. Git °æ±¾¹ý¾É
Git 1.8 °æ±¾Ö®Ç°²»Ö§³Ö gitignore Îļþ¡£È·±£Ê¹ÓÃ×îа汾µÄ Git¡£
4. ÎļþÔÚ Git Öб»ÒýÓÃ
ÈôÊÇÒ»¸öÎļþ±»Ìí¼Óµ½ Git ÖУ¬×ÝÈ»ËüÔÚ gitignore ÎļþÖУ¬ËüÒ²²»»á±»ºöÂÔ¡£Òª½â¾ö´ËÎÊÌ⣬ÇëʹÓÃÒÔÏÂÏÂÁî´Ó Git ÖÐɾ³ý¸ÃÎļþ£º
git rm --cached
µÇ¼ºó¸´ÖÆ
5. ºöÂÔ¹æÔò±»ÁýÕÖ
ÈôÊÇÔÚ gitignore ÎļþÖаüÀ¨ÁËÒ»¸ö¸üÏêϸµÄ¹æÔòÀ´ÁýÕÖÒ»¸ö¸üͨÓõĹæÔò£¬Ôò¸üͨÓõĹæÔò½«±»ºöÂÔ¡£ÀýÈ磬ÈôÊÇ gitignore Îļþ°üÀ¨ÒÔÏÂģʽ£º
/logs /logs/important.log
µÇ¼ºó¸´ÖÆ
ÄÇô “/logs/important.log” ½«²»»á±»ºöÂÔ£¬ÓÉÓÚÓиüÏêϸµÄ¹æÔòÔÚºöÂÔ “/logs” ÖеÄÎļþ¡£
6. ²Ù×÷ϵͳÎÊÌâ
ÔÚ Windows ÉÏ£¬gitignore ÎļþÖеÄ·¾¶ÐèҪʹÓÃÕýб¸Ü (/) ¶ø²»ÊÇ·´Ð±¸Ü ()¡£±ðµÄ£¬È·±£ gitignore ÎļþµÄ»»ÐзûʹÓõÄÊÇ LF (Unix) ¶ø²»ÊÇ CRLF (Windows)¡£
7. ÆäËûÔµ¹ÊÔÓÉ
- ÎļþϵͳȨÏÞÎÊÌâ
- ÌØÊâ×Ö·ûÔÚ gitignore ÎļþÖв»±»×¼È·´¦Öóͷ£
- ·À²¡¶¾Èí¼þ×ÌÈÅ
ÒÔÉϾÍÊÇgitignoreÎļþÆð²»ÁË×÷ÓÃÔõô½â¾öµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡