git - git diff 和 gif diff-index 有什么区别

标签 git

想获取git diff文件的时候,发现有人用

git diff-index --cached  --diff-filter=AM --name-only  HEAD

如果我使用

git diff --cached --diff-filter=AM --name-only  HEAD 

可以得到相同的结果。 那么 git diffgit 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/

相关文章:

GitHub pull 请求 : How to merge and fast-forward to avoid "recent changes" and diff notifications

没有远程名称,git 无法第一次 checkout 分支

git - 如何在 git 中添加另一个存储库?

git - 如何在 Git 中显示所有已提交但尚未推送的内容?

php - 从 php 脚本运行 git pull

perl - 使用Git显示所有一级后代分支

Git-缺少一些文件

git - git worktree 中的 .git 目录不是目录

linux - Git 大文件存储/如何在 AWS EC2 Linux 上安装 git lfs 2/"No package git-lfs available."

git - 在 Windows git pull and clone for Google cloud repository pop 凭据管理器对话框