Commit a Change
Once a change has been made to a project, it is possible to commit the change to Git. Committing is how we tell Git to make a changeset or snapshot of our project.
Committing changes is a two-step process. First new changes must be added to the staging area. The staging area is how Git distinguishes between the changes we want to commit versus those we do not. Only changes in the staging area can be committed.
Adding to the staging area
To add a specific file to the staging area, we would use the git add
command from within the project folder followed by the file's path.
# Add index.html to the staging area
git add index.html
It is possible to add multiple files to the staging area by using different options.
# Add all files that end in .html
git add *.html
# Add all files in the CSS directory
git add CSS/*
# Add all files everywhere
git add --all
Committing the Changes
Once a file has been added to the staging area, it can be committed using the git commit
command. Each time a commit is made, it is important to add a short message that describes what the commit or changes are doing. We add a message by using the -m
option followed by the message in quotes.
git commit -m "Adds an index.html to my project."
Commit Messages
While there are few requirements for commit messages, there are best practices for what kind of messages should be added to commits.
- Messages should be short single-line summaries (less than 50 characters). A complete description can be added to the summary after a blank line.
- Messages should be written in the present tense, not past tense.
- Messages should be clear and descriptive