############################################## ############################################## # GIT Cheat's ############################################## Initial ######## URLs git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6.git git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git git://git.kernel.org/pub/scm/linux/kernel/git/acme/pahole.git http://sources.redhat.com/git/systemtap.git ######## Reference Clone # git-clone --reference ./linux-2.6 git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6.git net-2.6 ######## New Project (aka initial import) New Project # mkdir hack_session; cd hack_session # git init-db # git add . # git commit -m "initial commit" ############################################## Change Repository ######## Checkout Revert a file local # git checkout -- Revert all local files # git checkout -f ######## Commit Commit everything what changed since last commit with a SoB message (display with "git diff HEAD") # git commit -a -s ######## Branches Create a branch # git branch -f or # git branch workingbranch master # git checkout workingbranch Show all branches # git branch ######## Merges # typical workflow git checkout -b topic-branch vim hack.c git commit # merge git checkout master git merge topic-branch git branch -d topic-branch # or merge as one comit git checkout master git merge --squash --no-commit topic branch git commit git branch -d topic-branch ######## Rebase git rebase master topic-branch-2 # rebase conflicts git rebase {--continue | --abort | --skip} # helpful git rebase -i ############################################## See what happend -- Gather Information ######## Diff See what you commit if you commit # git diff HEAD ######## Log Display what changed since a defined amount of time # git log --since='2 days ago' Display log between current branch (HEAD) and master # git log master..HEAD As usual, the best way to get some grip on a particular subsystem would tend to be with some script like. List by commiters # git log --no-merges v2.6.18.. drivers/usb | git shortlog | less -S ######## Blame Display who wrote a specific lime of code # git blame ######## Show Display what changed through the specific commit # git show ######## Patch Generate a patch for diff between master and HEAD # git format-patch master..HEAD Generate a patch for the last local commit with SoB message and ignore introduced whitespace errors and generate a nice looking subject line ([PATCH n/m] ...) the C option detect copies # git format-patch -s -b -n -C -1 Generate a delta between you branch and the master branch (HEAD is an alias for your working branch) # git format-patch master workingbranch ############################################## Subversion and GIT Initialize a repo (like git init): # git-svn clone https://libhashish.svn.sourceforge.net/svnroot/libhashish Do some work, and then commit your new changes to SVN, as well as automatically updating your working HEAD: # git svn dcommit Something has been committed to trunk, rebase the latest into your branch: # git svn rebase ############################################## Find A Bug (good luck) Bisect the source # git bisect start # git bisect bad # git bisect good v2.6.13-rc2 # git bad or # git good # git bisect reset ############################################## Additional Information ######## Send patch via mutt Generate a patch (git format-patch) and invoke mutt via -H # mutt -H 00*.patch ######## Send multiple patches Send multiple patches via git-send-email and compose an introduction email, but first generate all patches: # git format-patch -C -n -1 # git send-email --compose --suppress-from --to 00*.patch ######## Apply patched received via mutt Save the patch (as a normal attachment), go to the git repo and type # git am ######## Record the current stat fix something immediately without loosing current process # git stash edit emergency fix and commit fix # vim buggy.c # git commit -a -m "fix bug" and restart work git stash apply ######## Global Configuration # ~/.gitconfig [user] name = "Hagen Paul Pfeifer" email = "hagen@jauu.net" [sendemail] bcc = hagen@jauu.net chainreplyto = false smtpserver = /home/pfeifer/bin/sendmail.sh [color] status = auto diff = auto branch = auto ui = auto [color "branch"] current = yellow reverse local = yellow remote = green [color "diff"] meta = yellow bold frag = magenta bold old = red bold new = green bold [color "status"] added = yellow changed = green untracked = cyan [alias] st = status ci = commit co = checkout # list all new commits after you fetched, with stats, but excluding merges lc = log ORIG_HEAD.. --stat --no-merges # timezone aware version llog = log --date=local # fires up a git daemon for the repo you are currently in # connect simply by git ls-remote git://127.0.0.1/ clone et cetera serve = !git daemon --reuseaddr --verbose --base-path=. --export-all ./.git gb = branch -av [core] legacyheaders = false excludesfile = /home/pfeifer/.gitignore [repack] usedeltabaseoffset = true ######## The upper sendmail script: #!/bin/sh exec /usr/bin/ssh -T pfeifer@0xdef.net /usr/sbin/sendmail "$@"