Staging and Committing Changes
git add, git commit, commit message, git log, staged changes, untracked files
Staging and Committing Changes
Committing is the act of saving a snapshot of your staged changes to the repository history. Every commit captures a point in time you can return to later.
Staging Files
To stage a single file, run git add filename.txt. To stage all changes at once, run git add . (the dot means the current directory and everything inside it).
Staging gives you control. You can stage only the files relevant to one logical change and commit them, leaving other work in progress unstaged. This keeps your history clean and meaningful.
Creating a Commit
Once files are staged, commit them:
git commit -m "Add initial project structure"The -m flag lets you write the commit message inline. Always write messages in the imperative mood and keep them under 72 characters. Good examples: Fix login bug, Add user authentication, Update README with setup instructions.
Viewing Commit History
Run git log to see all commits in the current branch. Each entry shows the commit hash, author, date, and message. For a compact view, use git log --oneline. To see a graphical branch history, use git log --oneline --graph --all.
Amending the Last Commit
If you made a typo in your last commit message or forgot to include a file, amend it before pushing:
git commit --amend -m "Corrected commit message"Only amend commits that have not been pushed to a shared repository.
