stackademic

The leading education platform for anyone with an interest in software development.

Git Commit

Snapshot changes with meaningful messages and staged files

Overview

A commit records a snapshot of staged changes in your repository history. Good commits are small, focused, and described with clear messages so teammates (and future you) understand why a change was made.

Syntax / Usage

# Stage files
git add file.ts
git add .                    # all changes in current directory
git add -p                   # interactive hunks

# Commit
git commit -m "Add user login form validation"
git commit -m "Title" -m "Body with more context"

# Amend last commit (unpushed only)
git commit --amend

# View history
git log --oneline -10
git show HEAD

Conventional commit format (optional):

feat(auth): add OAuth callback handler
fix(api): handle null user id
docs: update README install steps

Examples

Stage only related changes for a focused commit:

git add src/auth/login.ts src/auth/login.test.ts
git commit -m "fix(auth): reject empty password on login"

Review what will be committed:

git status
git diff --staged

Common Mistakes

  • Committing secrets (.env, API keys)—use .gitignore and rotate keys
  • Giant commits mixing unrelated refactors and features
  • Vague messages like "fix stuff" or "wip"
  • Committing broken code to shared branches without running tests

See Also

branch stash remote clone