我知道.gitignore文件會掩蓋Git版本控制中的指定文件。 我有一個項目(LaTeX),它在運行時會生成許多其餘文件(.auth,.dvi,.pdf,日誌等),但我不但願這些文件被跟蹤。 php
我知道我能夠(也許應該這樣作)將全部這些文件放在項目的單獨子文件夾中,由於這樣我就能夠忽略該文件夾了。 html
可是,是否有任何可行的方法將輸出文件保留在項目樹的根目錄中,並使用.gitignore忽略除我正在使用Git跟蹤的文件之外的全部內容? 就像是 jquery
# Ignore everything * # But not these files... script.pl template.latex # etc...
要忽略目錄中的某些文件,必須以正確的順序執行此操做: git
例如,忽略文件夾「 application」中的全部內容,但index.php和文件夾「 config」中要注意該順序 。 github
您必須否認要先想要的東西。 web
失敗 app
application/*
ide
!application/config/*
this
!application/index.php
spa
做品
!application/config/*
!application/index.php
application/*
若是要忽略目錄中除其中一個文件以外的所有內容,能夠爲文件路徑中的每一個目錄編寫一對規則。 例如.gitignore忽略pippo文件夾,除了pippo / pluto / paperino.xml
pippo/* !pippo/pluto pippo/pluto/* !pippo/pluto/paperino.xml
更具體一點:
示例:忽略webroot/cache
全部內容-但保留webroot/cache/.htaccess
。
請注意cache
文件夾後的斜槓(/):
失敗
webroot/cache* !webroot/cache/.htaccess
做品
webroot/cache/* !webroot/cache/.htaccess
我有來自涼亭的Jquery和Angular。 Bower將它們安裝在
/public_html/bower_components/jquery/dist/bunch-of-jquery-files /public_html/bower_components/jquery/src/bunch-of-jquery-source-files /public_html/bower_components/angular/angular-files
最小化的jquery在dist
目錄中,angular在angular
目錄中。 我只須要將最小化的文件提交到github。 一些篡改.gitignore,這是我設法想到的...
/public_html/bower_components/jquery/* !public_html/bower_components/jquery/dist /public_html/bower_components/jquery/dist/* !public_html/bower_components/jquery/dist/jquery.min.js /public_html/bower_components/angular/* !public_html/bower_components/angular/angular.min.js
但願有人能發現這個有用。
在大多數狀況下,您想使用/*
代替*
或*/
使用*
是有效的,可是它能夠遞歸工做。 今後之後,它就再也不查找目錄。 人們建議再次使用!*/
將目錄列入白名單,但最好使用/*
將最高級別的文件夾列入黑名單
# Blacklist files/folders in same directory as the .gitignore file /* # Whitelist some files !.gitignore !README.md # Ignore all files named .DS_Store or ending with .log **/.DS_Store **.log # Whitelist folder/a/b1/ and folder/a/b2/ # trailing "/" is optional for folders, may match file though. # "/" is NOT optional when followed by a * !folder/ folder/* !folder/a/ folder/a/* !folder/a/b1/ !folder/a/b2/ !folder/a/file.txt # Adding to the above, this also works... !/folder/a/deeply /folder/a/deeply/* !/folder/a/deeply/nested /folder/a/deeply/nested/* !/folder/a/deeply/nested/subfolder
上面的代碼將忽略.gitignore
, README.md
, folder/a/file.txt
, folder/a/b1/
和folder/a/b2/
全部文件,以及後兩個文件夾中的全部文件。 (而.DS_Store
和*.log
文件將在這些文件夾中被忽略。)
顯然,我也能夠執行!/folder
或!/.gitignore
。
更多信息: http : //git-scm.com/docs/gitignore