git log --pretty 🎯Welcome to this comprehensive guide on using the powerful command git log --pretty! This tutorial is designed for both beginners and intermediate learners, so let's get started. 🎉
Git is a version control system that helps developers manage changes to their codebase, collaborate with others, and track the history of their projects. It's essential for any serious software development work.
git log is a command that displays the commit history of your Git repository. By default, it shows the commit's hash, author, date, and message. However, we'll focus on using the --pretty option, which lets us customize the output to make it more readable and meaningful.
git log --pretty 🎯The --pretty option allows you to control the format of the output. This can be particularly useful when dealing with large commit histories or when you need to quickly understand the sequence of events in your project.
To start, let's see how to use basic formatting with git log --pretty.
git log --pretty=format:"%h - %an, %ar : %s"Here's what each part means:
%h: Commit hash%an: Author name%ar: Author date (relative)%s: Commit message subjectNow, let's make things more interesting by adding some extra details to our output.
git log --pretty=format:"\
%h\t%an\t%ad\t%s\n\
%b"In this example, we've added:
%ad: Author date (full)\n: New line%b: Commit message bodyLet's create a simple project and demonstrate the power of git log --pretty.
mkdir my-project && cd my-projectgit init
echo "Hello, World!" > readme.md
git add .
git commit -m "Initial commit"git log --pretty.echo "Hello, CodeYourCraft!" >> readme.md
git add .
git commit -m "Add welcome message"
git log --pretty=format:"\
%h\t%an\t%ad\t%s\n\
%b"You should see output similar to the following:
5e93864 Your Name 3 days ago Add welcome message
Initial commit
Hello, World!
Hello, CodeYourCraft!
What does the `%h` placeholder represent in `git log --pretty`?
Now that you've learned the basics of git log --pretty, you can customize the output of your Git commit history to better understand the changes in your projects. Happy coding! 💻🎓🔧