Chris Walquist's blog

21 November 2011

My beginner’s notes on using Git effectively

Filed under: information technology — walquis @ 6:08 pm

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 tutorialtrac.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 –aggressiveNot 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 -w
head, threshold = ARGV
head ||= 'HEAD'
threshold ||= 1 # Megabyte
big_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
end
end
big_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

13 September 2011

vim tips – diw, daw, gqip, gf

Filed under: nutrition — Tags: — walquis @ 3:57 pm

diw – delete in word – deletes word under cursor
daw – deletes word, and following whitespace.
gqip – format inner paragraph, and place cursor on last line.
gf – Go to file whose name is under the cursor.

“What process is listening on TCP port X?” – fuser

Filed under: nutrition — Tags: — walquis @ 3:48 pm

/sbin/fuser -v 80/tcp # Path to fuser on RHEL Linux

“Display info about processes that are using the specified file or filesystem or socket”.  If run as root, this command shows the name of the process listening on TCP port 80.  fuser has many more uses and options.

Older Posts »

Powered by WordPress