When working with Git, it’s often useful to view the files that were committed in the last commit. This can help you verify the changes made and ensure that everything is as expected.
To view the last commit, you can use several Git commands. One of the most straightforward ways is to use git log
with the --name-status
option. This will display a list of files that were added, modified, or deleted in the last commit.
Here’s an example:
$ git log --name-status HEAD^..HEAD
This command tells Git to show the log of commits between the current commit (HEAD
) and the previous commit (HEAD^
). The --name-status
option displays the names of the files that were changed, along with their status (added, modified, or deleted).
Alternatively, you can use git show
with the --summary
option to view a summary of the last commit:
$ git show --summary
This command will display the names of created or removed files, but not the names of changed files.
If you want to see only the names of files that were changed in the last commit, without any additional information, you can use git show
with the --name-only
option:
$ git show --name-only
This command will list just the files that were modified in the last commit.
Another way to view the last commit is to use git log
with the -1
option, which displays only the most recent commit:
$ git log -1
You can also add the --stat
option to display a summary of the changes made in the last commit:
$ git log -1 --stat
These commands provide different ways to view the last commit, depending on your needs. By using these commands, you can easily verify the changes made in the last commit and ensure that everything is as expected.