A git cheat sheet to get you started

Here is a list of useful git commands I have compiled over the past few years. Although you should absolutely learn git the hard way by making mistakes, breaking things and swearing at your terminal, you might need to get things done now. Here is a git cheat sheet that will get you through most common situations.

# Undo all changes since last commit
git reset --hard HEAD

# Undo all changes since last commit for a single file
git checkout [file]

# See git diff, but only show changed files
git diff --name-only [commit]

# Show the hash of the very first commit
git rev-list HEAD | tail -n 1

#Remove the file from git, but don't delete it
git rm --cached [file]

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax