A Hodge-Podge of Basic Git
Understanding staging, index, and cache Git for computer scientists - Brief intro. Lots of git commands and diagrammed results. Includes git rebase, git merge remotes/../.., git clone, git tag. Restoring lost commits - How to reverse e.g. "git reset --hard HEAD^". gitready.com is good at clear explanations. git fsck, git reflog, git merge, git show-ref. Interactive rebasing - Scott Chacon (author of the Pro-Git book) runs this site. He knows his stuff. Git Treeishes - Scott's. http://book.git-scm.com Git Log - Also Scott's. Cool options for graphing, topo-order, etc., such as git log --pretty=format:"%h %s" --graph Managing Remotes - From help.github.com. git remote prune, git remote rename, git push, etc. Best MacOsx Git Client - SourceTree Tig - graphical history viewer in Curses. Download/install instructions git svn tutorial - trac.parrot.org
git diff --staged -- diff staged against committed
git log -p -- diff per-commit ("patch")
git reset HEAD <file> -- Unstage <file>
git remote show origin
git update-ref
git reflog -- Show previous values of HEAD and other commit pointers
git tag -a annotated
git log --name-status --abbrev-commit --relative-date --graph --pretty=format:"%h "cd %an"
git push origin [tagname] -- Like pushing a branch
git push origin --tags -- Push all tags along w/branch
git reset --hard HEAD^ -- Set HEAD to the (1st) parent of HEAD (Throw away most recent commit)
git fsck --lost-found -- Show dangling commits
git checkout -b newbranch -- Create newbranch & switch to it (NOTE: "git branch newbranch" creates the branch, but does not switch to it!)
For Administrators
Getting rid of unwanted history
git gc –aggressive - Not usually a good idea, according to Linus Torvalds (from 6 Dec 2007). Only applies when “I know I have a really bad pack, and I want to throw away all the bad packing decisions I have done”. Nice explanation of how git delta-chains work.
A Ruby script for finding big files in Git history:
#!/usr/bin/env ruby -whead, threshold = ARGVhead ||= 'HEAD'threshold ||= 1 # Megabytebig_files = {}`git rev-list #{head}`.split("\n").each do |commit| `git ls-tree -zrl #{commit}`.split("\0").each do |object| bits, type, sha, size, path = object.split(/\s+/, 5) size = size.to_i big_files[sha] = [path, size, commit] if size >= threshold.to_f * 1024 * 1024 endendbig_files.each do |sha, (path, size, commit)| where = `git show -s #{commit} --format='%h: %cr'`.chomp puts "%4.1fM\t%s\t(%s)" % [size.to_f/(1024*1024), path, where]end