Git

Last Updated: 7/26/2023

Viewing Commit

  • To see what we have changed in a given commit we use the show command
  • There are two ways to reference a commit

View using Id

  • We can reference it using its unique identifier. We don't have to type all the seven characters, we can type fewer characters, as long as we don't have another commit, whose ID starts with these characters.
git show identifier
git show 1a3f

View using HEAD

  • head is currently in front of the last commit
  • To view the last commit, we can type head
git show HEAD
  • To view the previous commits, type a tilde and then specify how many steps we want to go back.
git show HEAD~1
git show HEAD~2

View the file in the commit

git show HEAD~1:filepath
git show HEAD~1:.gitignore

View all files and directories in commit

  • Each commit contains a complete snapshot of our working directory, not just changes
  • If you want to see all the files and directories in a commit
git ls-tree HEAD~1
  • In git database, we have an object with ID generated based on content
  • Files are represented using blobs, and directories are represented using trees
  • All the objects are stored in git database. Using the show command, we can easily view an object in git database.
  • Using the show command, we can view an object in gits database. These objects can be commits, blobs, which represent files, and trees which represent directories, as well as tags.
git show identifier
git show 51912