1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58:01 +00:00

Add List Just The Files Involved In A Commit as a git til

This commit is contained in:
jbranchaud
2021-02-19 17:07:54 -06:00
parent 29af66b988
commit 66a3ae1f54
2 changed files with 31 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
_1054 TILs and counting..._
_1055 TILs and counting..._
---
@@ -253,6 +253,7 @@ _1054 TILs and counting..._
- [List Commits On A Branch](git/list-commits-on-a-branch.md)
- [List Different Commits Between Two Branches](git/list-different-commits-between-two-branches.md)
- [List Filenames Without The Diffs](git/list-filenames-without-the-diffs.md)
- [List Just The Files Involved In A Commit](git/list-just-the-files-involved-in-a-commit.md)
- [List Most Git Commands](git/list-most-git-commands.md)
- [List Untracked Files](git/list-untracked-files.md)
- [Move The Latest Commit To A New Branch](git/move-the-latest-commit-to-a-new-branch.md)

View File

@@ -0,0 +1,29 @@
# List Just The Files Involved In A Commit
As part of a script I was writing I needed a command that could list out all
the files involved in a given commit. The `git-show` command (which is
considered a porcelain command) can do this but isn't ideal for scripting. It
is recommended to instead use _plumbing_ commands.
The `git-diff-tree` command is perfect for listing blobs (files) involved in a
commit.
```bash
$ git diff-tree --no-commit-id --name-only -r <SHA>
```
The `--no-commit-id` flag suppresses the output of the commit id, because we
want just the files. The `--name-only` flag tells the command to suppress other
file info and to only show the file names. The `-r` flag tells the command to
recurse into subtrees so that you get full pathnames instead of just the
top-level directory.
If you're interested, the `git-show` parallel to this is:
```bash
$ git show --pretty="" --name-only <SHA>
```
See `man git-diff-tree` and `man git-show` for more details on these.
[source](https://stackoverflow.com/questions/424071/how-to-list-all-the-files-in-a-commit)