Skip to content

Instantly share code, notes, and snippets.

@lingtran
Last active April 14, 2016 16:04
Show Gist options
  • Save lingtran/9addeb0e94860117e260a4739b3ffd75 to your computer and use it in GitHub Desktop.
Save lingtran/9addeb0e94860117e260a4739b3ffd75 to your computer and use it in GitHub Desktop.

Git commands & what they do

  • git stash

    • Stashes away dirty working directory in order to return to a clean working directory, when there is the desire to record the current state of the working directory and the index before going back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.
    • 'save' is default --> so, really git stash save if want to be explicit
    • Resource: https://git-scm.com/docs/git-stash
  • git stash apply

    • Restores modifications that were stored away
    • Beware that it may potentially be restored on top of a different commit
  • git shortlog

  • git commit --amend

    • Replaces the tip of the current branch by creating a new commit. The message from the original commit is used as the starting point when no other message is specified in the command line via flag options -m, -F, -c.
    • git commit --amend --no-edit amends a commit without changing its commit message
    • https://git-scm.com/docs/git-commit
  • git reset --hard

  • git reset --soft

    • Does not touch the index file or the working tree at all (but resets the head to , just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.
  • git reset --hard HEAD~2

    • (?) Rewind the master branch to get rid of those two commits.
  • Three different ways to display the git log:

Useful GithHub keyboard shortcuts:

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