Git Add and Commit
Add and Commit
Section titled “Add and Commit”Purpose
Section titled “Purpose”Stage changes and create commits with clear history entries.
Commands
Section titled “Commands”git add <file>
- Stage a specific file
- Use when you want to commit only selected changes
- Example:
git add src/app.py
git add .
- Stage all tracked and untracked changes in the current directory tree
- Use when all current changes belong in the same commit
git commit -m "<message>"
- Create a commit from staged changes
- Use after reviewing what is staged
- Example:
git commit -m "Fix login validation"
git commit -am "<message>"
- Stage modified tracked files and commit in one step
- Use for quick commits when no new files need to be added
git commit -amdoes not include new untracked files- Review staged changes with
git diff --cachedbefore committing when the change set matters