[英]Git diff ignore
是否可以在git diff期間忽略某些文件? 我對過濾掉Makefile.in,Makefile,configure(以及所有自動生成的廢話)特別感興趣。
您可以嘗試將文件列表傳遞給git diff
,它將僅對那些文件執行diff。
根據您的代碼設置方式,它可以很簡單:
git diff otherbranchname -- src/ # only give me diffs from src/
或像以下那樣難看/復雜:
git diff otherbranchname -- $( git ls-files |
perl -lne'next if /(?:[mM]akefile(?:\.in)?|configure|whateverelse)/;print' )
# diff all files which don't match the pattern
根據您要忽略的文件是否由當前分支中的Git管理,您需要用find *
替換git ls-files
; 改用find .
並將|.git
添加到Perl表達式中。
按您認為合適的方式進行調整,可能使用您知道要比較的目錄/文件名,而不是使用git ls-files
或find
。
另一個類似的解決方案(添加到.git/config
):
[alias]
mydiff = !git diff -- $(git diff --name-only | grep -Ev "([mM]akefile|configure)")
然后運行:
git mydiff
請注意, git diff --name-only
優於git ls-files
因為它會將較短的文件列表傳遞給git diff
,因為將僅包含經過修改的文件。 使用git ls-files
時,我遇到了超過大型項目中最大參數數量的麻煩。
關於gitignore和自動工具集成,您可能對git.mk感興趣: http : //mail.gnome.org/archives/desktop-devel-list/2009-April/msg00211.html
如此處詳述,您可以使用exclude
路徑規范魔術
git diff -- . ':(exclude)Makefile*' ':(exclude)configure'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.