git commit
git commit saves the changes currently staged in Git as a checkpoint with a message.
What you will learn
- How the working tree, staging area, and repository relate
- How to create a commit with a clear message
- How to review what will be saved before committing
Minimal workflow
git status; git add index.html; git diff --staged; git commit -m "Update the home page"Only staged changes are included. A commit message should describe the change so that you and your collaborators can understand the history later.
Common options and mistakes
git commit -astages modifications and deletions to tracked files, but not new files.git commit --amendreplaces the latest commit; avoid rewriting a commit that others already pulled.- Review
git diff --stagedbefore committing so unrelated or secret files do not enter history.