Skip to main content

Command Palette

Search for a command to run...

Git Commit, Git Show, and Git Checkout

Updated
4 min readView as Markdown
Git Commit, Git Show, and Git Checkout
K
Hi, I’m Khushi Dubey. I work with Cloud and DevOps technologies, with a focus on AWS, Linux, Docker, Kubernetes, Terraform, and CI/CD. Here, I document my hands-on work, technical experiments, and things I learn while working with infrastructure and automation.

What is Git?

Before we start, let’s quickly understand what Git is. Git is like a time machine for your code. It helps you save different versions of your work, so you can go back to an older version if something goes wrong. It’s also great for collaborating with others on the same project.

Now, let’s talk about the three commands:


1. Git Commit: Saving Your Work

Think of Git Commit as taking a snapshot of your work. When you’re working on a project, you make changes to your files. Once you’re happy with those changes, you can save them using git commit.

Step-by-Step: How to Commit

  1. Make Changes: Edit your files (e.g., add new code, fix a bug, or write some text).

  2. Stage Your Changes: Before committing, you need to tell Git which changes you want to save. Use the command:

    Copy

     git add <file-name>
    

    For example, if you changed a file called script.js, you’d type:

    Copy

     git add script.js
    

    If you want to stage all your changes, you can use:

    Copy

     git add .
    
  3. Commit Your Changes: Now, save your changes with a message describing what you did. Use:

    Copy

     git commit -m "Your message here"
    

    For example:

    Copy

     git commit -m "Fixed the login button issue"
    

    This saves your changes in Git’s history.

Why is this useful?
Commits let you save your progress step by step. If something breaks later, you can always go back to a previous commit.


2. Git Show: Viewing a Commit

Once you’ve made a commit, you might want to see what changes were made in that commit. That’s where Git Show comes in. It’s like opening a photo album to look at a specific snapshot.

Step-by-Step: How to Use Git Show

  1. Find the Commit ID: Every commit has a unique ID (a long string of numbers and letters). You can find it by running:

    Copy

     git log
    

    This shows a list of all your commits. Look for the commit you want to inspect and copy its ID (you only need the first few characters).

  2. View the Commit: Use the git show command followed by the commit ID:

    Copy

     git show <commit-id>
    

    For example:

    Copy

     git show 1a2b3c4
    

    This will show you the changes made in that commit, including which lines were added or removed.

Why is this useful?
It helps you understand what was changed in a specific commit, which is great for debugging or reviewing your work.


3. Git Checkout: Switching Between Versions

Git Checkout is like a time-traveling tool. It lets you switch between different versions of your project. You can go back to an old commit or switch to a different branch (a separate version of your project).

Step-by-Step: How to Use Git Checkout

  1. Find the Commit or Branch: Use git log to see a list of commits or git branch to see a list of branches.

  2. Switch to a Commit: If you want to go back to a specific commit, use:

    Copy

     git checkout <commit-id>
    

    For example:

    Copy

     git checkout 1a2b3c4
    

    This will take you back to the state of your project at that commit. (Note: This puts you in a “detached HEAD” state, which means you’re not on a branch. To go back, you can switch to a branch using git checkout main or git checkout master.)

  3. Switch to a Branch: If you want to switch to a different branch, use:

    Copy

     git checkout <branch-name>
    

    For example:

    Copy

     git checkout feature-login
    

    This switches your project to the feature-login branch.

Why is this useful?
It lets you explore different versions of your project without losing your current work. You can always switch back to where you were.


Quick Recap

  • Git Commit: Save your changes with a message.

  • Git Show: View the details of a specific commit.

  • Git Checkout: Switch between different versions or branches.


linkedin: https://www.linkedin.com/in/khushi-dubey-6036a2305

Thank You!

N

This was exactly what I needed to read today. Thanks for putting it together.

More from this blog

Git & GitHub Diaries

11 posts