Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I list all of the files in a commit?

Tags:

git

git-show

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 (SHA-1), with no extraneous information.

I have tried:

git show a303aa90779efdd2f6b9d90693e2cbbbe4613c1d 

Although it lists the files, it also includes unwanted diff information for each.

Is there another git command that will provide just the list I want, so that I can avoid parsing it from the git show output?

like image 733
Philip Fourie Avatar asked Jan 08 '09 12:01

Philip Fourie


People also ask

How do you check what files are in a commit?

To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.

How do you check what files are being committed in git?

In Git, we can use git show commit_id --name-only to list all the committed files that are going to push to the remote repository.


1 Answers

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
like image 183
Ryan McGeary Avatar answered Oct 03 '22 11:10

Ryan McGeary