http://ndpsoftware.com/git-cheatsheet.html

Table of Contents

  1. Permanently Authenticating on OSX
  2. Common commands
  3. Emergency commands
    1. Delete a tag
    2. Revert
      1. Revert Commit(s) from the history by generating another commit that reverses the impact of the commit that you are trying to revert.
      2. Revert all unstaged changes
    3. Reset

Permanently Authenticating on OSX

Use the osxkeychain credential helper

Common commands

Purpose Command
Create a repository
cd projectDir
git init
Create a bare repository (on a USB stick, for transferring between networks)
cd projectDir
git init —-bare myrepo.git
# Then set this repo as the origin of a local repo
Checkout a branch
git checkout _branchName_

Commit changes
git add .		# add changed files to staging area
git commit -m "message" # Commit with a message
Status of repository
git status

Last commit message
git log -1 		# view last commit
git log -5 # view last 5 commits
git log -1 --pretty=%B # Prints just the commit message
Find commits containing ‘foo bar’ (source)
git log -S 'foo bar' --source --all

Emergency commands

Delete a tag

1
2
git tag -d _tagName_
git push origin :refs/tags/_tagName_

Revert

“Revert” reverts any public commits done on the repository (current branch).

Revert Commit(s) from the history by generating another commit that reverses the impact of the commit that you are trying to revert.

1
2
3
git commit -m "changes that will be reverted"
git revert HEAD # newset commit points to previous commit
git revert HEAD~2 # newset commit points to the commit 2 commits ago

Revert all unstaged changes

1
git checkout -- .  # . = all changed files

Reset

Reset CHANGES the history, whereas revert ADDS to the history. BEWARE! Is designed only for local changes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Create a new file called `foo.java` and add some code to it

# Commit it to the project history
git add foo.js
git commit -m "Start developing a crazy feature"

# Edit `foo.js` again and change some other tracked files, too

# Commit another snapshot
git commit -a -m "Continue my crazy feature"

# Decide to scrap the feature and remove the associated commits
git reset --hard HEAD~2