Git & GitHub
/Beginner
git commit
Definition
Captures a snapshot of the project's currently staged changes. Committed snapshots can be thought of as 'safe' versions of a project.
Explain Like I'm New
Taking the photograph. You staged your files, now you are pressing the camera shutter. It permanently saves the current state of the staged files into the Git history database, and requires you to write a short message explaining what you did.
Real World Example
Saving your progress at the end of the day. `git commit -m "Finished building the header navbar"`
Common Use Cases
- •Creating a permanent save point in history
Architecture & Flow
Terminal Output
bash / terminal
# Standard commit with a message
$ git commit -m "Fix navigation bug on mobile"
# Shortcut! Add ALL tracked files and commit them in one single command
$ git commit -a -m "Quickly save all my changes"
# (Note: -a does NOT include brand new, untracked files!)
# Oh no, I made a typo in my last commit message!
# --amend lets you overwrite the very last commit message:
$ git commit --amend -m "Fix navigation bug on mobile (for real this time)"
Interview Questions
basic
- What flag allows you to write the commit message directly in the command line?
intermediate
- What happens if you run `git commit` without the `-m` flag?