Git Commands
Git Shell Commands#
Reverting a Branch to a Previous Commit#
git reset --hard <SHA>
git push origin master -f
Reverting a single erroneous commit and keeping all others before and after#
Basically undoes everything in that commit and commits as a new commit. Example, you have commits A,B,C,D. You only want to get rid of C but can’t revert the entire branch to D and lose commits AB.
git revert <SHA>
git push origin master
Delete untracked files#
git clean -f -d
or
git checkout --
Search for Commit Message#
git log --grep=<pattern>
Reset Head to a Specific Branch#
Helpful when you are performing a merge and want to reset the branch to the repo
git fetch origin
git reset --hard origin/staging
Reset Master Branch to the Full Contents of Another Branch#
Use the ours merging strategy
git checkout master
git pull origin master
git checkout staging
git pull origin staging
git merge -s ours master
git checkout master
git merge staging
Tag an old commit#
git tag -a <version tag> <commit hash> -m "<message>"
git tag -a v1.2 9fceb02 -m "Message here"