暂存文件的 Git 列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33610682/
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-09 03:41:07  来源:igfitidea点击:

Git list of staged files

gitgit-diffgit-statusgit-stage

提问by Timon de Groot

I staged a lot of files using git add, now I want to see all the files I have staged, without untrackedfiles or changed but unstagedfiles.

我使用 暂存了很多文件git add,现在我想查看我暂存的所有文件,没有未跟踪的文件或已更改但未暂存的文件。

How do I do that? When using git diff --cachedI can see the changes of what I just staged. So then I tried using git status --cachedbut that --cachedunfortunately doesn't work on git status.

我怎么做?使用时git diff --cached我可以看到我刚刚上演的内容的变化。然后我尝试使用,git status --cached--cached不幸的是这不适用于git status.

回答by Timon de Groot

The best way to do this is by running the command:

执行此操作的最佳方法是运行以下命令:

git diff --name-only --cached

When you check the manual you will likely find the following:

当您查看手册时,您可能会发现以下内容:

--name-only
    Show only names of changed files.

And on the examplepart of the manual:

在手册的示例部分:

git diff --cached
    Changes between the index and your last commit.

Combined together you get the changes between the index and your last commitand Show only names of changed files.

结合在一起你得到changes between the index and your last commitShow only names of changed files.

Update: --stagedis also available as an alias for --cachedabove in more recent git versions.

更新:在最近的 git 版本中--staged也可以作为--cached上面的别名使用。