How to list all the files in a commit?

后端 未结 30 2364
一个人的身影
一个人的身影 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:21

    There's also git whatchanged, which is more low level than git log

    NAME
           git-whatchanged - Show logs with difference each commit introduces
    

    It outputs the commit summary with a list of files beneath it with their modes and if there added(A), deleted(D) or modified(M);

    $ git whatchanged f31a441398fb7834fde24c5b0c2974182a431363
    

    Would give something like:

    commit f31a441398fb7834fde24c5b0c2974182a431363
    Author: xx <xx@xx.nl>
    Date:   Tue Sep 29 17:23:22 2015 +0200
    
        added fb skd and XLForm
    
    :000000 100644 0000000... 90a20d7... A  Pods/Bolts/Bolts/Common/BFCancellationToken.h
    :000000 100644 0000000... b5006d0... A  Pods/Bolts/Bolts/Common/BFCancellationToken.m
    :000000 100644 0000000... 3e7b711... A  Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.h
    :000000 100644 0000000... 9c8a7ae... A  Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.m
    :000000 100644 0000000... bd6e7a1... A  Pods/Bolts/Bolts/Common/BFCancellationTokenSource.h
    :000000 100644 0000000... 947f725... A  Pods/Bolts/Bolts/Common/BFCancellationTokenSource.m
    :000000 100644 0000000... cf7dcdf... A  Pods/Bolts/Bolts/Common/BFDefines.h
    :000000 100644 0000000... 02af9ba... A  Pods/Bolts/Bolts/Common/BFExecutor.h
    :000000 100644 0000000... 292e27c... A  Pods/Bolts/Bolts/Common/BFExecutor.m
    :000000 100644 0000000... 827071d... A  Pods/Bolts/Bolts/Common/BFTask.h
    ...
    

    I know this answer doesn't really match "with no extraneous information.", but I still think this list is more useful then just the filenames.

    0 讨论(0)
  • 2020-11-22 02:21

    There is a simple trick to view as a file listing, just add : after the hash.

    git show 9d3a52c474:
    

    You can then drill in,

    git show 9d3a52c474:someDir/someOtherDir
    

    If you hit a file you'll get the raw version of the file; which sometimes is what you want if you're only looking for a nice reference or key pieces of code (diffs can make everything a mess),

    git show 9d3a52c474:someDir/someOtherDir/somefile
    

    Only drawback of this method is that it doesn't easily show a tree of files.

    0 讨论(0)
  • 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
    0 讨论(0)
  • 2020-11-22 02:23

    If you are using oh-my-zsh and git plugin, the glg shortcut is helpful.

    0 讨论(0)
  • 2020-11-22 02:25

    I like this:

    git diff --name-status <SHA1> <SHA1>^
    
    0 讨论(0)
  • 2020-11-22 02:25

    List all files in a commit tree:

    git ls-tree --name-only --full-tree a21e610
    
    0 讨论(0)
提交回复
热议问题