Created
June 26, 2014 21:45
-
-
Save ryancurtin/f3567007a5b5ca48436d to your computer and use it in GitHub Desktop.
Random git commands over the years
This file contains 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
# Force Pull (on a release, get updated production / preproduction) | |
------------------------------------------------------- | |
git fetch --all | |
git reset --hard origin/master | |
# Remove all untracked files | |
------------------------------------------------------- | |
git clean -f | |
# Create a local version of a remote branch | |
------------------------------------------------------- | |
git checkout -b experimental origin/experimental | |
# Undo git reset | |
------------------------------------------------------- | |
git reset HEAD@{1} | |
# Reset github repo (BE CAREFUL) | |
------------------------------------------------------- | |
git reset --hard <old-commit-id> | |
git push -f | |
# Go back N commits | |
------------------------------------------------------- | |
git reset --soft HEAD~2 (going back 2 commits) | |
# Squash merge N commits | |
------------------------------------------------------- | |
git rebase -i HEAD~4 (merging last 4 commits) | |
pick 01d1124 Adding license | |
squash 6340aaa Moving license into its own file | |
squash ebfd367 Jekyll has become self-aware. | |
squash 30e0ccb Changed the tagline in the binary, too. | |
* selecting 'pick' on the first commit squashes all 4 commits into that one | |
# Show diff from specific commit | |
------------------------------------------------------- | |
git show $COMMIT | |
# Undo adding file for commit | |
------------------------------------------------------- | |
git reset HEAD <file> | |
# Change git colors | |
------------------------------------------------------- | |
Either use .gitconfig or: | |
git config --global color.ui auto | |
git config --global color.diff true | |
# Show only file names for a commit | |
-------------------------------------------------------- | |
git show --pretty="format:" --name-only [SHA] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment