File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010
1111For a steady stream of TILs, [ sign up for my newsletter] ( https://tinyletter.com/jbranchaud ) .
1212
13- _ 1054 TILs and counting..._
13+ _ 1055 TILs and counting..._
1414
1515---
1616
@@ -253,6 +253,7 @@ _1054 TILs and counting..._
253253- [ List Commits On A Branch] ( git/list-commits-on-a-branch.md )
254254- [ List Different Commits Between Two Branches] ( git/list-different-commits-between-two-branches.md )
255255- [ List Filenames Without The Diffs] ( git/list-filenames-without-the-diffs.md )
256+ - [ List Just The Files Involved In A Commit] ( git/list-just-the-files-involved-in-a-commit.md )
256257- [ List Most Git Commands] ( git/list-most-git-commands.md )
257258- [ List Untracked Files] ( git/list-untracked-files.md )
258259- [ Move The Latest Commit To A New Branch] ( git/move-the-latest-commit-to-a-new-branch.md )
Original file line number Diff line number Diff line change 1+ # List Just The Files Involved In A Commit
2+
3+ As part of a script I was writing I needed a command that could list out all
4+ the files involved in a given commit. The ` git-show ` command (which is
5+ considered a porcelain command) can do this but isn't ideal for scripting. It
6+ is recommended to instead use _ plumbing_ commands.
7+
8+ The ` git-diff-tree ` command is perfect for listing blobs (files) involved in a
9+ commit.
10+
11+ ``` bash
12+ $ git diff-tree --no-commit-id --name-only -r < SHA>
13+ ```
14+
15+ The ` --no-commit-id ` flag suppresses the output of the commit id, because we
16+ want just the files. The ` --name-only ` flag tells the command to suppress other
17+ file info and to only show the file names. The ` -r ` flag tells the command to
18+ recurse into subtrees so that you get full pathnames instead of just the
19+ top-level directory.
20+
21+ If you're interested, the ` git-show ` parallel to this is:
22+
23+ ``` bash
24+ $ git show --pretty=" " --name-only < SHA>
25+ ```
26+
27+ See ` man git-diff-tree ` and ` man git-show ` for more details on these.
28+
29+ [ source] ( https://stackoverflow.com/questions/424071/how-to-list-all-the-files-in-a-commit )
You can’t perform that action at this time.
0 commit comments