Git commands
# reset changes to a file
# http://stackoverflow.com/a/1817774
#
# Abort a merge (conflict), as of version 1.6.1
# https://stackoverflow.com/a/102309
git reset --merge
# Assuming you did not commit the file, or add it to the index, then:
git checkout filename
# Assuming you added it to the index, but did not commit it, then:
git reset HEAD filename
git checkout filename
# Assuming you did commit it, then:
git checkout origin/master filename
# Assuming you want to blow away all commits from your branch (VERY DESTRUCTIVE):
git reset --hard origin/master
# reset local repo to point to remote state
# All local commits not common to the remote will be gone.
# http://stackoverflow.com/a/6284819
git fetch origin
git reset --hard origin/master
# list authors of a project
# http://www.commandlinefu.com/commands/view/4519/list-all-authors-of-a-particular-git-project
git log --format='%aN' | sort -u
# ordered by commits
git shortlog -s -n | cut -c8-
# gives you the tracking info for the branches
# http://stackoverflow.com/a/12538667
git branch -vv
# Cleaning local stale branches
git remote prune origin
# fetch and automatically prunes all stale references
git fetch -p
# update remote
git remote set-url origin <URL>
# Show updated remote
git remote -v
# change a branch to be the master using strategy=ours
# http://stackoverflow.com/a/2763118
# Bundling a repo into a single file (for emailing around or backup)
# http://stackoverflow.com/a/5578292
git bundle create /tmp/repo.git_bundle --all
# show diff of stash indexed at 0 (latest stash)
git stash show -p stash@{0}
# Checking out submodules
# https://stackoverflow.com/a/11358126
git clone <repo url> --recursive
# if you already cloned but forgot --recursive
git submodule update --init
# Reverting changes to submodules
# https://stackoverflow.com/a/17871677
git submodule foreach --recursive git reset --hard
# Check if a hash is present in checked out repo
# https://stackoverflow.com/a/18516021
git cat-file -t <hash>