Skip to content

Instantly share code, notes, and snippets.

@kamiboers
Last active April 14, 2016 16:01
Show Gist options
  • Save kamiboers/862e605a19ed1a93c8434739df2c1bf4 to your computer and use it in GitHub Desktop.
Save kamiboers/862e605a19ed1a93c8434739df2c1bf4 to your computer and use it in GitHub Desktop.

Git Commands

  • git stash is used to temporarily store the uncommitted changes that you've made on one branch in order to go and work on another branch without being forced to commit files that aren't ready to be committed.
  • git stash apply applys the changes from the most recent stash when you return to the branch. You can view all previous stashes with git stash list, and apply changes from a specific stash with git stash apply stash@{#}, where # is the stash id.
  • git shortlog summarizes the git log output, and can be modified to provide a numbered list (-n) or summary (-s), among several other options accessible at git shortlog --help.
  • git commit --amend is used to edit local commit messages. In order to alter the version pushed to github, a force command must be used.
  • git reset --hard resets the index and the working tree. Any changes to tracked files in the working tree since the last commit are discarded.
  • git reset --soft does not reset the index or working tree, but resets the head to the most recent commit. All changed files are now 'Changes to be committed', and changes are not lost.
  • git reset --hard HEAD~2 permanently resets your head to two commits ago. This should never be done if the commits that you are discarding have been shared with anyone. Bad (rebasing) things will happen.

Find three different ways to display the git log. One example is git log --oneline.

  • git log --stat displays a summary of changes made in each commit (insertions/deletions/removals/etc.)
  • git log -n displays the n most recent commits.
  • git log --after --before displays commits within a given date range.
  • git log --pretty=format"options" displays a neat row-by-row list of each commit with requested details. Example: "git log --pretty=format:"Commit Hash: %H, Author: %aN, Date: %aD""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment