想获取git diff文件的时候,发现有人用
git diff-index --cached --diff-filter=AM --name-only HEAD
如果我使用
git diff --cached --diff-filter=AM --name-only HEAD
可以得到相同的结果。
那么 git diff
和 git diff-index
有什么区别呢?
什么时候必须使用 git diff-index
而不是 git diff
?
最佳答案
git diff-index
是与索引或工作树的差异:
Compares the content and mode of the blobs found in a tree object with the corresponding tracked files in the working tree, or with the corresponding paths in the index
git diff
更通用,可以比较两个文件,或两个提交,或(如 diff-index)树和索引。
在您的情况下,diff HEAD
确实会将 HEAD 与索引进行 diff,diff-index
也会这样做。
关于git - git diff 和 gif diff-index 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24197606/