DEV Community

Jeremy
Jeremy

Posted on • Originally published at blog.notgrm.dev

Review the content of your last Git commit

The other when working on one of my side projects, I needed to review the changes that I have made in my previous commit. For this kind of need, I usually browse to Github to review commits or look for a specific file in VS Code; but I could not use any of these methods as my project did not have a remote repository on Github and I wanted to see all the changes made across the whole project.

So I fallback to read Git documentation again to finally found the right command to help me review the changes of my last commit.

git log --patch -1
Enter fullscreen mode Exit fullscreen mode
  • The β€”patch option display the commit diff for each commit of my Git history
  • The -1 option limit the number of displayed commits to only 1 (the most recent of the current branch)
Author: Jeremy Bertrand <my_email@example.org>
Date:   Fri Feb 18 15:16:31 2022 +0000

    chore: update the database config to support remote db

diff --git a/config/database.yml b/config/database.yml
index da4b691..2d92ba5 100644
--- a/config/database.yml
+++ b/config/database.yml
@@ -17,6 +17,9 @@
 default: &default
   adapter: postgresql
   encoding: unicode
+  username: <%= ENV.fetch("POSTGRES_USER") { "pg_user" } %>
+  password: <%= ENV.fetch("POSTGRES_PASSWORD") { "pg_password" } %>
+  host: <%= ENV.fetch("POSTGRES_HOST") { "127.0.0.1" } %>
Enter fullscreen mode Exit fullscreen mode

It is also possible to use an other Git command to achieve the same result which can be used to see any Git objects using their reference, and use HEAD as default value if no object is passed.

git show
Enter fullscreen mode Exit fullscreen mode

For better rendering of Git diffs, I strongly recommend you to use the delta utility

Want more?

Top comments (0)