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
git - diff of current changes before committing
提问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 diff
by 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 --staged
does 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):
- https://git-scm.com/book/en/v2(most chapters; it explains the model behind Git and answers most of typical questions)
- and then immediately http://gitready.com/(usage tips).
- https://git-scm.com/book/en/v2(大部分章节;它解释了 Git 背后的模型并回答了大多数典型问题)
- 然后立即http://gitready.com/(使用技巧)。
回答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 add
ed files, use the staged
flag:
要查看以前git add
编辑过的文件的更改,请使用以下staged
标志:
git diff --staged