Last active
May 27, 2019 20:48
-
-
Save verticalgrain/d55856c38ed79f1de6329bfc0a800aaa to your computer and use it in GitHub Desktop.
Git cheatsheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Checkout by hash: | |
git checkout 970327a74bce000242e08b0d6aeaa19ed03add7c | |
// To get back to normal branch: | |
git checkout master | |
// Git log only merges: | |
git log --merges | |
// Remove files from the tree | |
// First add the file name to .gitignore, then | |
git rm --cached <file-name> | |
// Directory: | |
git rm -r --cached directory/ | |
// Undo a git pull or git merge before it's been committed or pushed | |
git reflog // Pick the hash of the commit you want to roll back to | |
git reset --hard c03fd373 | |
// Undo a git add & git commit (before push) | |
git reset HEAD^\ | |
// Check if any files have whitespace issues or merge conflict marks | |
git diff --check master | |
// Archive old merged branches, locally and remotely | |
git tag archive/mybranch mybranch | |
git branch -D mybranch | |
git push origin :mybranch | |
// Check what branches have NOT been merged into a certain branch (feature/whatever) | |
git branch --no-merged feature/whatever | |
// Git stash! | |
git stash // Stash the currently unstaged files | |
git stash list // list the stashes | |
git stash apply // apply the most recent stash | |
git stash apply stash@{2} // Apply a specific stash | |
git stash show -p | git apply -R // Unapply the most recent stash | |
git stash show -p stash@{0} | git apply -R // Unapply a specific stash | |
$ git config --global alias.stash-unapply '!git stash show -p | git apply -R' // Make an alias that does stash unapply |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment