ฉันมักจะติดอยู่ที่ไหนสักแห่งในเรื่องนี้แม้จะกลับมาที่คำถามนี้หลายครั้ง ฉันคิดขั้นตอนอย่างละเอียดในการทำอย่างเป็นขั้นตอน:
ก่อนอื่นเพียงใช้git addเพื่อเพิ่มเนื้อหาจริง
มันจะแสดงไฟล์ที่เกี่ยวข้องที่เพิ่มเข้าไปในดัชนีขณะที่คนอื่น ๆ ยังไม่ได้ติดตาม สิ่งนี้ช่วยในการปรับโครงสร้างอย่างเป็น.gitignoreขั้นเป็นตอน
$ git add wp-content/themes/my-theme/*
$ git status
Changes to be committed:
new file: wp-content/themes/my-theme/index.php
new file: wp-content/themes/my-theme/style.css
Untracked files:
wp-admin/
wp-content/plugins/
wp-content/themes/twentyeleven/
wp-content/themes/twentytwelve/
...
wp-includes/
...
เพิ่มDUMMY.TXTไฟล์ชั่วคราวในไดเรกทอรีของคุณ:
$ git status
Changes to be committed:
new file: wp-content/themes/my-theme/index.php
new file: wp-content/themes/my-theme/style.css
Untracked files:
wp-admin/
wp-content/plugins/
wp-content/themes/twentyeleven/
wp-content/themes/twentytwelve/
...
wp-content/themes/my-theme/DUMMY.TXT <<<
...
wp-includes/
...
เป้าหมายของเราในตอนนี้คือการสร้างกฎเพื่อDUMMY.TXTให้เป็นสิ่งเดียวที่ยังคงปรากฏว่าไม่ได้ติดตามเมื่อเราเสร็จแล้ว
เริ่มเพิ่มกฎ:
.gitignore
/*
สิ่งแรกคือเพียงเพิกเฉยต่อทุกสิ่ง ไฟล์ที่ไม่ได้ติดตามจะหายไปทั้งหมดควรแสดงเฉพาะไฟล์ที่มีการจัดทำดัชนี:
$ git status
Changes to be committed:
new file: wp-content/themes/my-theme/index.php
new file: wp-content/themes/my-theme/style.css
เพิ่ม dir แรกในเส้นทาง wp-content
/*
!/wp-content
ตอนนี้ไฟล์ที่ไม่ได้ติดตามจะปรากฏขึ้นอีกครั้ง แต่มีเพียงwp-contentเนื้อหาของ
$ git status
Changes to be committed:
new file: wp-content/themes/my-theme/index.php
new file: wp-content/themes/my-theme/style.css
Untracked files:
wp-content/plugins/
wp-content/themes/twentyeleven/
wp-content/themes/twentytwelve/
..
ละเว้นทุกสิ่งใน dir แรก/wp-content/*และยกเลิกการเพิกเฉย!/wp-content/themes
/*
!/wp-content
/wp-content/*
!/wp-content/themes
ตอนนี้ไฟล์ที่ไม่ได้ติดตามจะถูก จำกัด ให้แคบลงเท่านั้น wp-content/themes
$ git status
Changes to be committed:
new file: wp-content/themes/my-theme/index.php
new file: wp-content/themes/my-theme/style.css
Untracked files:
wp-content/themes/twentyeleven/
wp-content/themes/twentytwelve/
..
ทำขั้นตอนนี้ซ้ำจนกระทั่งไฟล์จำลองนั้นเป็นไฟล์เดียวที่ยังคงแสดงว่าไม่ได้ติดตาม:
/*
!/wp-content
/wp-content/*
!/wp-content/themes
/wp-content/themes/*
!/wp-content/themes/my-theme
$ git status
Changes to be committed:
new file: wp-content/themes/my-theme/index.php
new file: wp-content/themes/my-theme/style.css
Untracked files:
wp-content/themes/my-theme/DUMMY.TXT
**ไวด์การ์ดใช้งานได้เฉพาะในกรณีที่คุณไม่มีสแลชในรูปแบบของคุณโปรดดูsparethought.wordpress.com/2011/07/19/…