How can I get a list of files in a git commit?

This question already has an answer here:

  • How to list all the files in a commit? 25 answers

  • How can I get the list of committed files on the master branch?

    git ls-tree lists the contents of a tree object. By default, it lists the permission, type, hash, and associated filename of each object referenced in the tree object, but you can tell it to print only the filename by using the --name-only option.

    git ls-tree --name-only master
    

    Edit (thanks Alex): you also probably want to use the -r flag to recurse into subtrees (ie the tree objects "nested" inside the top tree object of your commit).

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

    I usually use

    git ls-files
    

    In the given plain form, it simply prints out the files committed in the current branch. To view files of a different branch, add the --with-tree parameter:

    git ls-files --with-tree=master
    

    lists all files of the master branch.

    The docs of git ls-files provide more fine tuning possibilities.

    链接地址: http://www.djcxy.com/p/26646.html

    上一篇: 如何通过提交SHA获取文件和内容

    下一篇: 我如何获得git commit中的文件列表?