linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
Intro
Lessons
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Chapters
  • How it works
  • Lessons
  • Knowledge base
  • Interview prep
home/git/kb/Everyday workflow/commit-cmd

kb/workflow ── Everyday workflow ── beginner

git commit

Captures what is in the index as a new commit object and moves the current branch to that commit. Without arguments it opens an editor for the message; the most common form uses `-m`.

view as markdownaka: git-commit-cmd, commit-command

git commit is the moment when "edits" become "history". It takes a snapshot of the index (not the working tree) and packages it into a commit object.

What happens during a commit

  1. A tree object is assembled from the index (via write-tree).
  2. A commit object is created: tree + parent (HEAD) + author + committer + message. Author is who wrote the changes; committer is who recorded them. They usually match, but after a rebase, cherry-pick, or applied patch the committer is updated while the author stays the same.
  3. The current branch moves to the new commit SHA.
  4. HEAD follows the branch automatically.

See chapter 4 of the textbook (plumbing) for a detailed walkthrough.

Basic forms

bash
git commit                       # opens editor for the message
git commit -m "fix typo"         # short inline message
git commit -m "title" -m "body"  # title + blank line + body
git commit -a                    # auto-stage all tracked files
                                 # (equivalent to git add -u + commit)
git commit --amend               # rewrite the last commit

--amend

The most common special mode. Does not create a new commit; it rewrites the HEAD commit. Use it to:

  • add a forgotten file (git add forgot.js && git commit --amend)
  • fix the message (git commit --amend -m "new message")
  • keep the message but update the content (git commit --amend --no-edit)

After --amend the old commit remains in .git/objects/ as a dangling object. git reflog will see it for about a month.

Important: if the commit was already pushed, --amend creates a conflict on the next push. Either use push --force-with-lease, or create a new commit instead of amending.

Commit message

A convention that originated in the Linux kernel and is now widely adopted:

area: short description in imperative mood
More detail, if needed. What and why,
not how. The code explains how. Wrap at 72 characters.
Closes #123

First line at most 50 characters, in imperative mood (add, fix, not added or adds). Blank line. Body only when you need to explain the motivation or warn about subtleties.

Pitfalls

  • git commit commits the index, not the working tree. If you forgot git add, the changes will not be included.
  • git commit -am "..." (via -a) auto-stages only modified tracked files. New untracked files are excluded. Those always need an explicit git add.
  • An empty commit fails without a flag. If you need one (for example, to mark a release), use git commit --allow-empty -m "release v1.0".

§ команды

bash
git commit -m "..."

Record the index with an inline message

bash
git commit -a -m "..."

Auto-stage all tracked files and commit (new untracked files are excluded)

bash
git commit --amend --no-edit

Fold the index into the last commit without changing the message

bash
git commit --allow-empty -m "release"

Create a commit with no changes (for tags, release markers)

§ см. также

  • addgit addMoves file changes from the working tree into the index (staging area). Does not commit anything. It only controls what goes into the next commit.
  • statusgit statusShows the difference between three Git zones: what is modified in the working tree, what is staged in the index, and which branch is active. The safest command in Git: it changes nothing and you can run it as often as you like.
  • loggit logTraverses the commit graph and prints each commit. By default it starts at HEAD and follows parents. A dozen flags cover 95% of history-browsing scenarios.
  • commitCommitA Git object: a snapshot of the entire project (via a tree) plus metadata including author, committer, date, parents, and message. The SHA of a commit includes the parent's SHA, which makes history cryptographically linked.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies