git 如何仅列出将提交的文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1814504/
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
How do I list just the files that would be committed?
提问by gene
Is there any way to get a list of files that will be committed when I type the following?
有什么方法可以获取我键入以下内容时将提交的文件列表?
git commit -m "my changes"
git status lists too much. I could strip out all the words, but I'd rather not. And I don't want to be told about untracked files.
git status 列表太多了。我可以去掉所有的字,但我宁愿不要。我不想被告知未跟踪的文件。
I've tried
我试过了
git ls-files -md
but that doesn't show files that have been recently added, but not yet committed.
但这不会显示最近添加但尚未提交的文件。
I'm looking for the same output you'd get from
我正在寻找与您相同的输出
svn status -q
For example
$ svn status -q
A file.py
M dir/database.py
M start.py
例如 $ svn status -q
A file.py
M dir/database.py
M start.py
回答by gene
This is what I was looking for. Thanks to notnoop for the lead I needed. I wanted to post back my solution in case it helps others.
这就是我一直在寻找的。感谢 notnoop 提供我需要的线索。我想发回我的解决方案,以防它对其他人有帮助。
git diff HEAD --name-only
Since I intended to do
因为我打算做
git commit -s -F mesage.txt
with the files found in the first line.
与在第一行中找到的文件。
My intent is to create a little system that totally ignores the index i.e. that I never need to do git add. (From what I understand, the index is useful when creating patches, which isn't by no means the norm in my workflow.)
我的意图是创建一个完全忽略索引的小系统,即我永远不需要执行 git add。(据我所知,索引在创建补丁时很有用,这绝不是我工作流程中的常态。)
回答by CB Bailey
This command will tell you what files in your index/cache/staging area differ from the current HEAD (and whether they are additions, modifications or deletions) which is the changes which will be committed if you use git commit
without explicit paths or the -a
option. It's format is reasonably similar to the svn status
output which you show.
此命令将告诉您索引/缓存/暂存区中的哪些文件与当前 HEAD 不同(以及它们是添加、修改还是删除),这是如果您在git commit
没有显式路径或-a
选项的情况下使用将提交的更改。它的格式与svn status
您显示的输出相当相似。
git diff --cached --name-status
回答by Murphy Danger
I know OP original asked to avoid git status
, but I felt this would be nice to leave for posterity (i.e other people who don't share OP's reservations).
我知道 OP 原先要求避免git status
,但我觉得这会很好地留给后代(即不同意 OP 保留意见的其他人)。
git status --porcelain | grep -v '^[ |??]' | sed -e 's/[A-Z] *//'
My reasoning is that git status --porcelain
seems like it was built for exactly this type of quandary...
我的理由是,它git status --porcelain
似乎就是为这种窘境而构建的......
source: http://git-scm.com/docs/git-status.html
来源:http: //git-scm.com/docs/git-status.html
EDIT:
You may chose to not use sed -e 's/[A-Z] *//'
if you wish to keep git's modification tags in front of each file name.
编辑:sed -e 's/[A-Z] *//'
如果您希望在每个文件名前保留 git 的修改标签,您可以选择不使用。
回答by notnoop
You can try:
你可以试试:
git diff --name-status
I get the following:
我得到以下信息:
$ git diff --name-status
M README.markdown
Without the untracked files.
没有未跟踪的文件。