Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get files and content by SHA of commit

Tags:

git

How to list files that are changed in specific commit and get content of that files when I have sha number of commit ?

like image 287
Damir Avatar asked Oct 07 '11 09:10

Damir


People also ask

How do I see files in a commit?

To find out which files changed in a given commit, use the git log --raw command.

How do I see all files 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.

How do I see files committed in git bash?

To see a list of commits with even more detail (including which files changed), run this command: git log --stat.


1 Answers

To list the files that were changed by a particular commit, you can do:

git show --name-only <commit>

If you want to suppress the log message from that output, you can add --pretty=format: to the options.

As for your second question, to see the content of a particular file from that commit, say with SHA1sum f414f31, you can do:

git show f414f31:Documentation/help.txt

... where the path Documentation/help.txt is relative to the top level of the working tree, regardless of whether you're in a subdirectory or not. If you need to extract a whole subdirectory, have a look at this question and answer:

  • What's the best way to extract a tree from a git repository?
like image 88
Mark Longair Avatar answered Oct 08 '22 02:10

Mark Longair