The message you wrote will help collaborators understand what you've done with your last commit, using prefix will help users distinguish which type of action your commit has performed, for example:
Here are two types of git message standards:
General
More specific
add = Create a capability e.g. feature, test, dependency.
cut = Remove a capability e.g. feature, test, dependency.
fix = Fix an issue e.g. bug, typo, accident, misstatement.
bump = Increase the version of something e.g. dependency.
make = Change the build process, or tooling, or infra.
start = Begin doing something; e.g. create a feature flag.
stop = End doing something; e.g. remove a feature flag.
refactor = A code change that MUST be just a refactoring.
style = Refactor of formatting, e.g. omit whitespace.
opt = Refactor of performance, e.g. speed up code.
doc = Refactor of documentation, e.g. help files.
Use alias
If you are using oh-my-zsh, you can use git plugin to add alias for your git commands. You can also create your own alias like this:
alias gs='git status'
alias als='alias | grep'
Then, use gs to check local modifications rather than git status. One can't remember all the aliases, now you can use als to search from them. For example:
Commit with -v option
Using this option, git will show all your modifications before you commit, recheck carefully before you commit !!!
git commit -v
The first time you use this commamd may throw this error: There was a problem with the editor 'vi'. You can solve it by setting default editor to vim:
git config --global core.editor /usr/bin/vim
Use rebase if you can
Rebase
Apply feat changes on master, cause one linear commit log.
# Way 1
git checkout feat
git rebase master
# Way 2
git rebase master feat
# Final
git checkout master
git merge feat
Merge
Diff feat and master, apply patch on feat.
# Way 1
git checkout feat
git merge master
# Way 2
git merge master feat
# Final
git checkout master
git merge feat
Reset your modifications
Here are some reset commands, only --hard option will destroy your data, be careful!
# reset unstaged(not added but modified) file (!!!)
git checkout -- <file>
# reset staged(added) file
git reset HEAD <file>
# drop commits without deleting modifed content
git reset --soft HEAD~1
# drop latest commit (!!!)
git reset --hard HEAD^
Other tips
Show all the branches
git branch -r
Comparison
# Compare one commit with the previous commit
git diff 96755a9~ 96755a9
# Show diff in a specific commit
git show 96755a9
Git message matters
The message you wrote will help collaborators understand what you've done with your last commit, using prefix will help users distinguish which type of action your commit has performed, for example:
Here are two types of git message standards:
General
More specific
add = Create a capability e.g. feature, test, dependency.
cut = Remove a capability e.g. feature, test, dependency.
fix = Fix an issue e.g. bug, typo, accident, misstatement.
bump = Increase the version of something e.g. dependency.
make = Change the build process, or tooling, or infra.
start = Begin doing something; e.g. create a feature flag.
stop = End doing something; e.g. remove a feature flag.
refactor = A code change that MUST be just a refactoring.
style = Refactor of formatting, e.g. omit whitespace.
opt = Refactor of performance, e.g. speed up code.
doc = Refactor of documentation, e.g. help files.
Use alias
If you are using oh-my-zsh, you can use git plugin to add alias for your git commands. You can also create your own alias like this:
Then, use
gs
to check local modifications rather thangit status
. One can't remember all the aliases, now you can useals
to search from them. For example:Commit with
-v
optionUsing this option, git will show all your modifications before you commit, recheck carefully before you commit !!!
The first time you use this commamd may throw this error:
There was a problem with the editor 'vi'.
You can solve it by setting default editor tovim
:Use rebase if you can
Rebase
Merge
Reset your modifications
Here are some reset commands, only
--hard
option will destroy your data, be careful!Other tips
Show all the branches
Comparison
How to see the changes in a commit?
Name your branch wisely
git branch naming best practices [closed]
Set Proxy
GIt Ignore
Git ignore's precedence. You can use it to ignore files locally.
Forget tracked file in gitignore
https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore
Commit Ignored files
Commit with no verify
--no-verify
: This option bypasses the pre-commit and commit-msg hooks.Force Push
Lifecycle of your edits