在git diff中同时显示暂存区和工作区?

64

如果我运行git diff,我将看到工作树中的更改,如果我运行git diff --staged(或--cached),那么我将看到已暂存的更改(使用git add)。但是,在git diff中是否有一种方法可以一次性查看所有更改?


7
这里有一张精美的图示,详细解释了git diff的不同类型!https://dev59.com/yHI-5IYBdhLWcg3w99oH#1587952 - swrobel
git status -v -v 将很快显示这个(git 2.3.4+,2015年第二季度)。请参见下面的答案 - VonC
3个回答

91

如果你指的是工作树和你的HEAD提交之间的更改(即已暂存和未暂存的更改),那么只需要执行以下操作:

git diff HEAD

2
不,OP想要“一次性看到所有内容”。 - krlmlr
6
git diff HEAD 显示了在一个 git diff 调用中所有的更改(已暂存和未暂存)。 - CB Bailey
@user946850:那不是重复的问题,因为它明确要求仅进行分阶段更改。我相信某个地方有一个重复的问题。 - CB Bailey
我并没有说它是完全重复的,而且我还没有找到“那个”完全重复的。 - krlmlr
我保证我已经努力查找了!不管怎样,感谢你的回答,这真的很有用。 - swrobel
显示剩余5条评论

35

有没有一种方法可以使用git diff一次性查看所有内容?

有的,从Git 2.4.0+(2015年4月)开始支持。

请参见提交4055500,作者为Michael J Gruber mjg

commit/status: show the index-worktree diff with -v -v (or -vv)

git commit and git status in long format show the diff between HEAD and the index when given -v. This allows previewing a commit to be made.

They also list tracked files with unstaged changes, but without a diff.

Introduce '-v -v' (or -vv) which shows the diff between the index and the worktree in addition to the HEAD index diff. This allows a review of unstaged changes which might be missing from the commit.

In the case of '-v -v' (or -vv), additional header lines

Changes to be committed:

and

Changes not staged for commit:

are inserted before the diffs, which are equal to those in the status part; the latter preceded by 50*- to make it stick out more.

在OP的情况下,简单的git status -v -v(或git status -vv)将显示已暂存和未暂存的差异。

1
如果有人没有意识到的话,你也可以组合使用标志:git status -vv - Subfuzion

4

Diffuse 可视化差异工具可以实现此功能:如果某些但不是全部更改已暂存,则会显示三个窗格。在冲突的情况下,甚至会有四个窗格。

Diffuse带有暂存和未暂存编辑的屏幕截图

使用以下命令调用:

diffuse -m

在您的Git工作副本中。

如果您问我,这是我见过的最好的视觉差异工具。


3
非常感谢您提供的好建议,但它并不完全回答了我的问题,因为我要求提供git命令来执行此操作。我将把其他的回答标记为答案... - swrobel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接