Skip to content

Instantly share code, notes, and snippets.

@ayamflow
Last active August 29, 2015 13:55
Show Gist options
  • Save ayamflow/8690726 to your computer and use it in GitHub Desktop.
Save ayamflow/8690726 to your computer and use it in GitHub Desktop.
Handy Git commands

Handy Git commands

  • Show list of commits with hash: git log
  • Show file at revision: git show REVISION:path/to/file
  • Roll back to revision: git reset --hard REVISION
  • Revert a file to revision: git checkout REVISION path/to/file
  • Get my colleague's file version during a merge: git checkout --theirs path/to/file
  • Add a remote : git remote add origin https://github.com/user/repo.git
  • Force unstash : git stash show -p | git apply && git stash drop
  • clone a branch: git clone -b <branch> <remote>
  • Better git log: https://coderwall.com/p/euwpig
  • Rebase master from branch: git checkout master && git rebase branch
  • Only push current branch with git push: git config --global push.default current
  • Create a branch from a commit: git branch <branch> <hash>
  • Find last revision of a file: git rev-list -n 1 HEAD -- <file>
  • Revert this file: git checkout <revision>~1 <file>
@kewah
Copy link

kewah commented Jan 29, 2014

  • unstage a file: git reset HEAD path/to/file
  • undo last commit and keep changes: git reset HEAD~1
  • stage parts of a changed file: git add -p
  • revert parts of a changed file: git checkout -p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment