Tech notes

Javascript, HTML, CSS

Mar 4, 2020 | git productivity

Oh git! Cheat list to resolve git problems


Git might be confusing and there are couple common cases that happen over and over again. This list contains some the most popular situations and commands to resolve them. Credits to ohshitgit.

Case Command & Explanation
Return back to specific state or stable version (before something bad has happened) git reflog to see a list of changes done in git acros all branches. Need to find index BEFORE wrong changes were made.
git reset HEAD@{index} reset git to specific state
Committed smth to master but it should have been on a brand new branch. git branch new-branch-name create a new branch from the current state of master
git reset HEAD~ --hard remove the last commit from the master branch
git checkout new-branch-name your commit lives in this new branch now
Merge a branch with a clean, linear history free of unnecessary merge commits git checkout branch-name checkout to the branch that needs to be merged
git rebase main to merge commits into master branch with linear order
git rebase -i HEAD~4 option -i opens additional UI dialog which allows to select, omit and reoder commits
Create a copy of specific commits from other branches into current branch git cherry pick commit1 commit2 followed by commits ID

More cases to come!

Great git tutoring game with awesome visualisation is here: learngitbranching.js.org


Back to blog