May I list the files of the current commit?

依然范特西╮ 提交于 2020-06-12 08:33:10

问题


Imagine that everytime I commit files, before I push them, I'd like to list them to check. How may I do that ?

I tried:

git ls-tree -r --name-only master
git ls-files -stage

If I edit a single file, add then commit it. If I try the above codes, it shows me all my files.

I want to list ONLY the files that will be pushed on the current commit.


回答1:


Git diff to the rescue on this one. You'll use the --name-only flag. To get the contents of the current commit, use this command:

#before stage
  git diff --name-only 
#staged changes before committing
  git diff --name-only --cached
#after committing
  git diff --name-only HEAD^ HEAD

If you want to see the files that you will be pushing if there is more than one commit, you'll need to specify your current branch head and the head on the remote

git diff --name-only remote/branch branch



回答2:


If you want to list files in the last commit (local or not), use this

git show --name-only



回答3:


As you say before the push, can i supposing that your work flow is git add then git commit then git push.

You can do the commit with the --short option link!

This will give you a output of all files change, add or delete in your that currently commit.

git commit --short -m "message for the commit"



来源:https://stackoverflow.com/questions/46205090/may-i-list-the-files-of-the-current-commit

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