gitÔõÑùºöÂÔÎļþ
ÔÚÏîÄ¿ÖУ¬ÎÒÃÇ¿ÉÄÜ»áÓöµ½Ò»Ð©²»ÐèÒª±» git ×·×ÙµÄÎļþ£¬ºÃ±È±àÒëÌìÉúµÄ¶þ½øÖÆÎļþ¡¢ÈÕÖ¾ÎļþÒÔ¼°ÔÝʱÎļþµÈ¡£´Ëʱ£¬git ÌṩÁËÒ»ÖÖºöÂÔÎļþµÄÒªÁ죬¿ÉÒÔºöÂÔÕâЩÎļþ£¬²î³ØÆä¾ÙÐа汾ÖÎÀí¡£
ÔÚ Git ÖУ¬ºöÂÔÎļþ½ÓÄɵÄÊÇ .gitignore Îļþ£¬¿ÉÒÔ¸æËß Git ºöÂÔÄÄЩÎļþ»òĿ¼²»±»×·×Ùµ½°æ±¾ÀúÊ·ÖС£ÔÚÕâƪÎÄÕÂÖУ¬ÎÒÃǽ«ÏÈÈÝ Git ÔõÑùºöÂÔÎļþ¡£
Ò»¡¢½¨Éè .gitignore Îļþ
½¨Éè .gitignore ÎļþºÜ¼òÆÓ£¬Ö»ÐèÒªÔÚÏîÄ¿¸ùĿ¼Öн¨ÉèÒ»¸öÃû×ÖΪ .gitignore µÄÎļþ¼´¿É¡£ÐèҪעÖصÄÊÇ£¬.gitignore ÎļþµÄÄÚÈݱØÐèƾ֤ Git µÄ¹æÔò¾ÙÐÐÉèÖá£ÏÂÃæÊÇÒ»¸ö .gitignore ÎļþµÄʾÀý£º
# ºöÂÔËùÓÐ .a Îļþ *.a # ¿ÉÊÇ lib.a Îļþ³ýÍâ !lib.a # ½ö½öºöÂÔÏîÄ¿¸ùĿ¼Ï嵀 TODO Îļþ£¬²»°üÀ¨ subdir/TODO /TODO # ºöÂÔ build/ Ŀ¼ÏµÄËùÓÐÎļþ build/ # ºöÂÔ doc/notes.txt Îļþ£¬µ«²»°üÀ¨ doc/server/arch.txt Îļþ doc/*.txt # ºöÂÔËùÓÐ .pdf ÎļþÔÚ doc/ Ŀ¼ÏÂÒÔ¼°×ÓĿ¼Ï doc/**/*.pdf
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊöʾÀýÖУ¬ÎÒÃÇ¿ÉÒÔ¿´µ½¶àÖÖÉèÖúöÂÔÎļþµÄ·½·¨¡£ÆäÖУ¬µÚÒ»ÐÐµÄ *.a ÌåÏÖºöÂÔËùÓÐµÄ .a Îļþ£¬!lib.a ÌåÏÖ²»ºöÂÔ lib.a Îļþ¡£/TODO ÌåÏÖºöÂÔÏîÄ¿¸ùĿ¼Ï嵀 TODO Îļþ£¬µ«²»°üÀ¨×ÓĿ¼Ï嵀 TODO Îļþ¡£build/ ÌåÏÖºöÂÔ build/ Ŀ¼ÏµÄËùÓÐÎļþ£¬doc/*.txt ÌåÏÖºöÂÔ doc/ Ŀ¼ÏµÄËùÓÐ .txt Îļþ£¬doc/**/*.pdf ÌåÏÖºöÂÔ doc/ Ŀ¼ÏÂÒÔ¼°×ÓĿ¼ÏµÄËùÓÐ .pdf Îļþ¡£ÔÚ .gitignore ÎļþÖУ¬ÎÒÃÇ»¹¿ÉÒÔʹÓà # ºÅÌåÏÖ×¢ÊÍ£¬ºÍ ! ºÅ×÷·ÏºöÂÔ¡£
¶þ¡¢ºöÂÔÒѾÌá½»µÄÎļþ
ÔÚÏîÄ¿ÖУ¬ÓÐʱ¼äÎÒÃÇÐèÒª¶ÔijЩÎļþ¾ÙÐкöÂÔ£¬¿ÉÊÇÕâЩÎļþÒѾÌá½»µ½ÁË Git ÖС£´Ëʱ£¬ÈôÊÇÎÒÃÇÐÞ¸ÄÁË .gitignore ÎļþÖеÄÄÚÈÝ£¬ÕâЩÎļþÈÔÈ»»á±»×·×Ùµ½°æ±¾ÀúÊ·ÖС£Òò´Ë£¬ÈôÊÇijЩÒѾÌá½»µÄÎļþÐèÒªºöÂÔ£¬ÎÒÃÇÐèҪʹÓà git rm –cached ÏÂÁîÀ´´Ó Git ÖÐɾ³ýÕâЩÎļþµÄ¼Í¼¡£
ÀýÈ磬ÈôÊÇÎÒÃÇÐèÒªºöÂÔ README.md Îļþ£¬¿ÉÊÇÕâ¸öÎļþÒѾÔÚ Git Öб»×·×Ùµ½ÁË°æ±¾ÀúÊ·ÖУ¬ÄÇôÎÒÃÇ¿ÉÒÔʹÓÃÈçÏÂÏÂÁ
git rm --cached README.md
µÇ¼ºó¸´ÖÆ
Ö´ÐÐÍêÕâ¸öÏÂÁîºó£¬README.md Îļþ²»»á±»´ÓÍâµØÎļþϵͳÖÐɾ³ý£¬Ö»ÊÇ´Ó Git µÄ°æ±¾¿âÖÐɾ³ý¡£´Ëʱ£¬ÎÒÃÇÔÙ½« README.md ÎļþÌí¼Óµ½ .gitignore ÖУ¬¾Í¿ÉÒÔÀֳɺöÂÔÕâ¸öÎļþÁË¡£
Èý¡¢ºöÂÔÎļþ¼Ð
ÔÚ Git ÖУ¬ÎÒÃDz»µ«¿ÉÒÔºöÂÔij¸öÎļþ£¬»¹¿ÉÒÔºöÂÔÒ»¸öÎļþ¼Ð¡£ÀýÈ磬ÈôÊÇÎÒÃÇÐèÒªºöÂÔ build/ Îļþ¼Ð£¬ÄÇôÎÒÃÇ¿ÉÒÔÔÚ .gitignore ÎļþÖÐÌí¼ÓÈçÏÂÄÚÈÝ£º
build/
µÇ¼ºó¸´ÖÆ
ÕâÑù£¬ËùÓÐ build/ Îļþ¼ÐÖеÄÎļþ¶¼»á±»ºöÂÔ£¬²»»á±» Git ×·×Ùµ½°æ±¾ÀúÊ·ÖС£
ËÄ¡¢×ܽá
ÔÚ¿ª·¢ÏîÄ¿ÖУ¬ºöÂÔÎļþÊÇÒ»¸ö³£¼ûµÄÐèÇó¡£Git ÌṩÁË .gitignore ÎļþÀ´×ÊÖúÎÒÃǺöÂÔ²»ÐèÒª±»×·×ÙµÄÎļþ¡£Í¨¹ý .gitignore Îļþ£¬ÎÒÃÇ¿ÉÒÔÉèÖúöÂÔÎļþµÄ¹æÔò£¬ºöÂÔijЩÎļþ»òÎļþ¼Ð£¬²î³ØÆä¾ÙÐа汾ÖÎÀí¡£ÈôÊÇÐèÒªºöÂÔÒѾÌá½»µ½ Git ÖеÄÎļþ£¬ÎÒÃÇÐèҪʹÓà git rm –cached ÏÂÁîÀ´É¾³ýÕâЩÎļþµÄ¼Í¼¡£¹ØÓÚÏîÄ¿ÖеÄÎļþÖÎÀí£¬ºöÂÔÎļþµÄÉèÖÃÊǺÜÊÇÓÐÓõļ¼ÇÉ¡£
ÒÔÉϾÍÊÇgitÔõÑùºöÂÔÎļþµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡