# Git List All Files Changed in a Single Commit

> Use git show with the name-only flag to list files in a commit, name-status to see how each file changed, and pretty=format to drop the commit message

**URL:** https://sentry.io/answers/list-all-files-in-a-git-commit/

---

## The Problem

How do I get a list of all files that were affected by a given commit in a Git repository?

## The Solution

The simplest way to do this is by using [`git show`](https://git-scm.com/docs/git-show) with the [`--name-only`](https://git-scm.com/docs/git-show#Documentation/git-show.txt---name-only) flag:

```bash
git show --name-only $COMMIT_HASH
```

This command will output the commit metadata, the commit message, and then a list of filenames that were added, modified, or deleted in the commit.

To see how each file was affected (added, modified, or deleted), we can use the [`--name-status`](https://git-scm.com/docs/git-show#Documentation/git-show.txt---name-status) flag instead:

```bash
git show --name-status $COMMIT_HASH 
```

To remove the commit message from the output, we can add the [`--oneline`](https://git-scm.com/docs/git-show#Documentation/git-show.txt---oneline) flag:

```bash
git show --name-only --oneline $COMMIT_HASH 
git show --name-status --oneline $COMMIT_HASH 
```

This will still show the commit metadata in the first line of the output. To produce an output containing only the names of affected files, we must specify [`--pretty`](https://git-scm.com/docs/git-show#Documentation/git-show.txt---prettyltformatgt) with an empty format string:

```bash
git show --name-only --pretty=format:
```

---

*Source: [sentry.io/answers/list-all-files-in-a-git-commit/](https://sentry.io/answers/list-all-files-in-a-git-commit/)*
