How to list all the files in a commit?

后端 未结 30 2314
一个人的身影
一个人的身影 2020-11-22 01:50

I am looking for a simple git command that provides a nicely formatted list of all files that were part of the commit given by a hash (SHA1), with no extraneous

30条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 02:22

    Preferred Way (because it's a plumbing command; meant to be programmatic):

    $ git diff-tree --no-commit-id --name-only -r bd61ad98
    index.html
    javascript/application.js
    javascript/ie6.js
    

    Another Way (less preferred for scripts, because it's a porcelain command; meant to be user-facing)

    $ git show --pretty="" --name-only bd61ad98    
    index.html
    javascript/application.js
    javascript/ie6.js
    

    • The --no-commit-id suppresses the commit ID output.
    • The --pretty argument specifies an empty format string to avoid the cruft at the beginning.
    • The --name-only argument shows only the file names that were affected (Thanks Hank). Use --name-status instead, if you want to see what happened to each file (Deleted, Modified, Added)
    • The -r argument is to recurse into sub-trees

提交回复
热议问题