Skip to content

Commit 66a3ae1

Browse files
committed
Add List Just The Files Involved In A Commit as a git til
1 parent 29af66b commit 66a3ae1

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For 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)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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)

0 commit comments

Comments
 (0)