Create an Empty Commit

GitGitBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In Git, a commit is a snapshot of the changes made to a repository. Each commit has a message that describes the changes made. Sometimes, you may need to create an empty commit with no changes to serve as a placeholder or to trigger a build process. In this challenge, you will learn how to create an empty commit in Git.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL git(("`Git`")) -.-> git/BasicOperationsGroup(["`Basic Operations`"]) git/BasicOperationsGroup -.-> git/commit("`Create Commit`") subgraph Lab Skills git/commit -.-> lab-12630{{"`Create an Empty Commit`"}} end

Create an Empty Commit

You need to create an empty commit in your Git repository. This can be useful in several scenarios, such as:

  • Triggering a build process
  • Creating a placeholder commit
  • Marking a specific point in the repository's history

Tasks

For this challenge, let's use the repository from https://github.com/labex-labs/git-playground.

  1. Navigate to the repository directory and configure your GitHub identity in the environment.
  2. Create an empty commit with the message "Empty commit".
  3. Verify that the empty commit was created.

This is where you run git log --name-status HEAD^..HEAD and the result:

Summary

Creating an empty commit in Git is a simple process that can be useful in several scenarios. Use the git commit --allow-empty -m <message> command to create an empty commit with the provided message.

Other Git Tutorials you may like