git - 提交前当前更改的差异

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9583527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:07:38  来源:igfitidea点击:

git - diff of current changes before committing

gitsshdiffmeld

提问by kikito

I have changed several files in a git repository, but have not committed them yet.

我已经更改了 git 存储库中的几个文件,但尚未提交。

I can get a list of the changes by just invoking git status. But how do I get a listing of the linesor the contentthat I have changed, in addition to the filenames?

我只需调用git status. 但是,除了文件名之外,我如何获得已更改的内容的列表?

I initially thought about using git diff, but it seems to be useful only for comparing already commited changes.

我最初考虑使用git diff,但它似乎只对比较已经提交的更改有用。

Usually I just do meld ., but on this case I'm connected to an external server via ssh.

通常我只是这样做meld .,但在这种情况下,我通过 ssh 连接到外部服务器。

回答by Mischa Arefiev

git diffby default shows difference between your working directoryand the index(staging areafor the next commit).

git diff默认情况下显示您的工作目录索引之间的差异(下一次提交的暂存区)。

If you have already added (staged) the changes to the staging area, git diff --stageddoes the job. Staging areais the data from which the next commit will be formed by git commit.

如果您已经添加(暂存)对暂存区的更改,git diff --staged则完成这项工作。 暂存区是由git commit.

P. S. Good reading (IMO) for Git beginners:

PS 适合 Git 初学者的良好阅读(IMO):

回答by EliuX

What i use for such cases is:

我在这种情况下使用的是:

git diff HEAD *

This will show the changes since last commit. Although somehow it works quicker with

这将显示自上次提交以来的更改。虽然不知何故它工作得更快

git diff .

or

或者

git diff

To see the changes on previously git added files, use the stagedflag:

要查看以前git add编辑过的文件的更改,请使用以下staged标志:

git diff --staged