07 / 09

What is a commit in Git?

In Git, a commit is a snapshot of your project's files at a specific point in time, effectively saving your work and creating a record of changes, including who made the changes, when, and what they did.

  1. 1

    Commits are created with the git commit command to capture the state of a project at that point in time.

  2. 2

    Git Snapshots are always committed to the local repository, each developer’s local repository is a buffer between their contributions and the central repository.

  3. 3

    Prior to the execution of git commit, the git add command is used to promote or 'stage' changes to the project that will be stored in a commit.

Difficulty: 2/10
Topics: commit creation, commit metadata, history manipulation

Scenario Questions

0-2 years experience
  1. 1

    You need to add a new feature file and push it to the repo. Walk me through how you would create a commit for that change.

  2. 2

    If you run git commit without specifying a message, what does Git do, and how would you fix it?

2-5 years experience
  1. 1

    During a code review you notice that a recent commit accidentally included a debug log file. How would you remove that file from the commit history without affecting other changes?

  2. 2

    Your CI pipeline fails because a commit was made with the wrong author email. Explain how you would amend the commit to correct the author information.

5-8 years experience
  1. 1

    In a large monorepo we have a policy limiting commit size to keep CI fast. How would you enforce and monitor commit size, and what trade‑offs does splitting commits introduce?

  2. 2

    When rebasing a long‑running feature branch, you encounter merge conflicts across many commits. Describe how you would resolve them while preserving a clean commit history.

8+ years experience
  1. 1

    Our organization is migrating from a centralized VCS to Git and wants a consistent commit strategy across dozens of teams. What guidelines would you establish for commit granularity, metadata, and signing, and how would you ensure adoption?

  2. 2

    We need to implement a system that automatically validates commit messages against a style guide before allowing pushes to protected branches. Outline the architecture and discuss potential impact on developer workflow.

Follow-up Questions

  • How does Git ensure commits are immutable?
  • What happens if you amend a commit that’s already been pushed?
  • Can you describe the role of the parent pointer in a merge commit?