How do I list just the files that would be committed?

六月ゝ 毕业季﹏ 提交于 2019-12-03 05:39:55

问题


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.

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


回答1:


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.

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.)




回答2:


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.

git diff --cached --name-status



回答3:


You can try:

git diff --name-status

I get the following:

$ git diff --name-status
M       README.markdown

Without the untracked files.




回答4:


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).

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...

source: 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.



来源:https://stackoverflow.com/questions/1814504/how-do-i-list-just-the-files-that-would-be-committed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!