M-A's

technology blog

Thursday 27 August 2009

git notes

This message is for me only. I don't not expect you learn anything from this or even think this is useful. This post represents a huge amount of fighting with blogspot editor.

WORN: git is similar to perl: write-once, read-never.

CONFIGURATION
  • git config --global color.ui auto (1.6+)
  • git config --global user.email me@me.com
  • git config --global user.name "Mini Me"
  • git config --global alias.st status
  • git config --global alias.br branch
  • Basically everything at http://git.wiki.kernel.org/index.php/Aliases#Shortcuts 
  • echo *.pyc>>.git/info/exclude
  • Edit these two in your ~/.gitconfig
    • [alias] 
    •   ignored = "!cd \"$(git rev-parse --show-cdup)\" && git clean -n -d | cut -c 14- | sed -e \"s/\\/$//\""
    •   ignoreall = "!cd \"$(git rev-parse --show-cdup)\" && git clean -n -d | cut -c 14- | sed -e \"s/\\/$//\" >> .git/info/exclude"
  • Use git-prompt! I use:
    • max_file_list_length=30
    • default_user=me
    • default_host=myhost
    • default_domain=mydomain
    • cwd_cmd='cwd_truncate 30'
    • and enable only the VCS I use.
  • Use git-completion.bash!
MODIFICATIONS

  • git remote add origin2 user@host:path/to/repo.git
  • git pull --rebase remote_name remote_branch
  • git svn clone svn://host/repo --stdlayout
  • git svn clone svn://host/repo -T sub/directory
    • You may want to use --prefix=origin/ but I like to just type "trunk" instead of "origin/trunk"
  • git svn rebase 
  • git push remote_name remote_branch 
    • remote_name and remote_branch are optional if branch.merge is set
  • git merge --squash --no-commit [other branch]
  • git mergetool --tool=kdiff3
    • when vimdiff is unsufficient and I'm on X
  • git cherry-pick (hash)
    • from the branch where you want to include your change
  • git checkout -b new_branch trunk
  • git checkout another_branch file_to_bring_here
    • another branch can be HEAD~1 for a past revision
    • note the file is implicitly "added" so git diff will not display anything, use git diff HEAD
  • git revert (hash)
  • git add .
  • git add -p
    • To index only some parts (hunks), useful to discard some changes by following with a commit and reset.
  • git reset "file"
    • Really the reverse of git add "file"
  • git commit -a -m "bleh"
  • git commit --amend
    • Modify the last commit
  • git branch -D branch_to_delete
  • git push origin :branch_to_delete
  • git reflog
    • To find a deleted branch back
  • git checkout -b new_branch HEAD@{1}
    • To revive it
  • git rebase -i default~2^
    • To squash or amend previous commits, reappend to previous head. Warning, rewrites history! ^ means rewrite on the parent 
  • git rebase --continue
    • Never rebase after pushing something!! Only merge!

QUERIES

  • git branch -a -v
  • git diff old..new
    • Every commit you can reach by new not reachable by new
  • git diff master...HEAD
    • reachable by either but not both, XOR
  • git diff master...
    • HEAD is implicit
  • git diff `git merge-base HEAD master`
    • refer to 3 commits before
  • git diff HEAD~3
  • git diff HEAD^^^
  • git diff HEAD^2
    • alternate parent
  • git diff master~2^2
    • headache, really
  • git log HEAD ^trunk
    • when trunk was updated, awesome
  • git log -p HEAD ^git-svn
    • full diff per log
  • git log --pretty=oneline
  • git log --pretty=format:"%h %an %ar - %s"
  • git log --pretty=format:"%h %an %ar - %s" --graph
  • git status
  • git clean -d -n -x
    • list currently ignored files
  • git blame -C1 file
    • search for renames
  • git diff --merge
    • for 3-way merge conflict
  • git show (hash)
    • will show how a merge conflict was fixed

Then read http://www.kernel.org/pub/software/scm/git/docs/user-manual.html

No comments: