This repository has been archived by the owner on May 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 185
How to Commit
Bryan Masamitsu Parsons edited this page Sep 25, 2018
·
1 revision
Simple Recipe:
- Make changes to one of more files:
echo "Hello World" > README.txt
- Stage the changes:
$ git add README.txt
- Commit the changes:
$ git commit -m "Created new README.txt file"
Detailed Recipe:
- Always check what branch you are on before you commit
git branch -av
git checkout my_branch
- It's usually a really good idea to pull and merge updates for the branch you are on before you try to commit to it.
git fetch --all
git merge origin/my_branch my_branch
- When creating a new source file, or modifying an existing file, use
git add
to "stage" the change:git add my_source_file.py
- Use git commit to create a way-point to which you can revert, or when your changes are finalized.
- Option A:
git commit my_source_file.py -m "Fixed a bug"
- Option B:
git commit my_source_file.py
- Option A:
- Fetch/pull updates to the branch you are working on before creating a new commit.
- This allows for what is called a "fast forward" merge, and prevents a lot of extra merging.
- Write useful commit messages
- Think of git commit messages as being part of a large log that can be searched later.
-
git log
output can be piped to grep and other GNU utilities. - the better the format and keywords included in the commit messages, the more useful the
git log
output becomes.
- Suggestions for making nice commit messages that make
git log
more useful:- Format the log message so that it is easier to read and search later
- explicitly list all affected files, classes, and methods in the commit message.
- If possible, keep each line below 60 characters so they don't wrap
- First line should be broadly descriptive, additional lines should include detail
- Place two line returns after the first line so that the display in
git log
is not made impossibly noisy.