Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想查看已添加到提交 ( git add something) 的文件的差异。我可以做这个:
git add something
git diff HEAD `git status -s | grep ^M | cut -c 4-`
有没有更短的方法?
您可以使用git diff --staged(或git diff --cached)查看提交时将使用的差异。
git diff --staged
git diff --cached
从手册页:
git diff [--options] --cached [<commit>] [--] [<path>...] 此表单用于查看您为下一次提交相对于命名的<commit>. 通常,您希望与最新提交进行比较,因此如果您不提供<commit>,则默认为HEAD. 如果HEAD不存在(例如未出生的分支)并且<commit>未给出,则显示所有阶段性更改。--staged是的同义词--cached。
git diff [--options] --cached [<commit>] [--] [<path>...]
<commit>
HEAD
--staged
--cached