Git 状态 - 有没有办法只显示特定目录中的更改?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/715321/
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 status - is there a way to show changes only in a specific directory?
提问by Kuba Suder
I would like to see a list of files modified since the last commit, as git status
shows, but I care only about files located in a single directory. Is there a way to do this? I tried git status <directory>
, but it seems this does something completely different (lists all changed files, as they would be if I wrote git add <directory>
first).
我想查看自上次提交以来修改的文件列表,如图git status
所示,但我只关心位于单个目录中的文件。有没有办法做到这一点?我试过git status <directory>
,但它似乎做了一些完全不同的事情(列出所有更改的文件,就像我git add <directory>
先写的那样)。
The documentation for git-status doesn't tell much, apart from the fact that it accepts the same options that git-commit does (but git-commit's purpose isn't to show lists of changed files).
除了它接受与 git-commit 相同的选项(但 git-commit 的目的不是显示已更改文件的列表)之外,git-status 的文档并没有说明太多内容。
回答by Sam Doidge
From within the directory:
从目录中:
git status .
You can use any path really, use this syntax:
您真的可以使用任何路径,请使用以下语法:
git status <directoryPath>
For instance for directory with path "my/cool/path/here"
例如对于路径为“my/cool/path/here”的目录
git status my/cool/path/here
回答by CB Bailey
The reason that git status
takes the same options as git commit
is that the purpose of git status
is to show what would happen if you committed with the same options as you passed to git status
. In this respect git status
is really git commit --preview
.
其原因git status
是采用相同的选项git commit
是的目的git status
是为了显示,如果你使用相同的选项致力于为您传递到会发生什么git status
。这方面git status
真是git commit --preview
。
To get what you want, you could do this which shows staged changes:
为了得到你想要的,你可以这样做,它显示了分阶段的变化:
git diff --stat --cached -- <directory_of_interest>
and this, which shows unstaged changes:
这显示了未分阶段的更改:
git diff --stat -- <directory_of_interest>
or this which shows both:
或者这两者都显示:
git diff --stat HEAD -- <directory_of_interest>
回答by Can Berk Güder
Simplest solution:
最简单的解决方案:
- Go to the directory
git status | grep -v '\.\.\/'
- 进入目录
git status | grep -v '\.\.\/'
Of course this discards colors.
当然,这会丢弃颜色。
回答by K-Gun
As a note, if you simplify to check git stats without going to git directory;
请注意,如果您简化检查 git stats 而不去 git 目录;
### create file sudo nano /usr/local/bin/gitstat ### put this in #!/usr/bin/env bash dir= if [[ $dir == "" ]]; then echo "Directory is required!" exit fi echo "Git stat for '$dir'." git --git-dir=$dir/.git --work-tree=$dir diff --stat ### give exec perm sudo chmod +x /usr/local/bin/gitstat
And calling that simple script: gitstat /path/to/foo-project
. You can also use it while in foo-project
just doing gitstat .
and so suppose shorter than git status -s
, git diff --stat
or git diff --stat HEAD
if your are always using console instead of gui's.
并调用那个简单的脚本:gitstat /path/to/foo-project
. 你也可以在foo-project
做的时候使用它gitstat .
,所以假设比 短git status -s
,git diff --stat
或者git diff --stat HEAD
如果你总是使用控制台而不是 gui。
Credits:
学分:
- @Charles Bailey: https://stackoverflow.com/a/715373/362780
- Git Status From Outside of the Working Directory
- @查尔斯贝利:https://stackoverflow.com/a/715373/362780
- 来自工作目录之外的 Git 状态