####################################################################### # GIT Cheat's ######## Git Dokus # http://www.kernel.org/pub/software/scm/git/docs/everyday.html # http://www.kernel.org/pub/software/scm/git/docs/tutorial.html # http://www.fieldses.org/~bfields/kernel/git.html # http://linux.yyz.us/git-howto.html # http://www.procode.org/stgit/ # http://www.jauu.net/var/cheats/001-git.txt ############### Git URL's rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git rsync://rsync.kernel.org/pub/scm/linux/kernel/git/axboe/blktrace.git rsync://rsync.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6.git rsync://rsync.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git rsync://rsync.kernel.org/pub/scm/linux/kernel/git/tglx/hrtimer-2.6.git rsync://rsync.kernel.org/pub/scm/network/ethtool/ethtool.git ############### New git repo # On a new project mkdir newProject # Initialise the .git directory which contains the repository git init-db vi file1.c vi file2.c git add *.c git commit # On an existing project cd project git init-db git add src/*.c git add inc/*.h git commit # Add files to a repository git add . git add path/to/new/file git-update-index --add path/to/new/file # Commit all changes git commit -a ############### Fast Forward Merge git-pull $URL # or git pull origin # or git pull # example git pull git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git ############### Pull tags rsync -a --verbose --stats --progress \ rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git/ \ .git/ # Checking files out of the repository git checkout # overwrite any of your local modifications (or Undo all local modifications) git-checkout -f # Colorfull short logs: cg-log -s -c # svn blame: git-whatchanged -p filename.c # show git env git-var -l Check in your own modifications (e.g. do some hacking, or apply a patch) # go to repository cd linux-2.6 # # # make some modifications vi drivers/net/sk98lin/skdim.c # # # NOTE: add '--add' and/or '--remove' if files were added or removed git-update-index # # # check in changes git commit ### List all changes in working dir, in diff format. #Display changes since last git-update-index: git diff # Display changes since last commit: git diff HEAD # Display the diff between two certain tags git diff v2.6.20-rc4..2.6.20-rc5 # or git diff a212ff3..3bb19 # Obtain summary of all changes in working dir git status # show the last change git show # List all changesets git log ######## Branches # List all branches (master is master) # the * indicates the current branch git branch # Make desired branch current in working directory git checkout -f $branch # Create new branch, start out with a head equal # to the one given as git-branch -f new-branch v2.6.18 # Create a new branch, and make it current git checkout -f -b my-new-branch-name master # Obtain a diff between current branch, and master branch # In most trees with branches, .git/refs/heads/master contains the current # 'vanilla' upstream tree, for easy diffing and merging. (in trees without # branches, 'master' simply contains your latest changes) git diff master..HEAD # Obtain a list of changes between current branch, and master branch # git log master..HEAD # or rather than full changeset descriptions, obtain a one-line summary of each # changes: # git log master..HEAD | git shortlog # Merge changes from one branch into another Let us suppose that you do work on # branch A and branch B, and after work on those two branches is complete, you # merge the work into mainline branch M. git checkout -f M # switch to branch M git pull . A # merge A into M git pull . B # merge B into M ############### Patches # To generate a ready-to-email-patch (with diffstat) execute # In front of this you must do a git-update-index and git commit git-format-patch master..HEAD ############### GIT Bisect # Binary search of a bug git bisect start git bisect bad git bisect good v2.6.13-rc2 # loop until the bug-introducing commit was found git bad # or git good git bisect reset ############### Logs # 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 ############### Misc. Debris # Apply all patches in a Berkeley mbox-format file # # First, make sure that the tools subdirectory of the git-core repository is in # your PATH. # cd my-kernel-tree-2.6 applymbox /path/to/mbox /path/to/signoff.txt # # The file /path/to/mbox is a Berkeley mbox file, containing one or more # patches to be committed to the git repository. The optional file # /path/to/signoff.txt is the text file that is appended to each changeset # description. For the Linux kernel, this typically includes the # # Signed-off-by: Your Name ############### Send Patch git format-patch master..HEAD --stdout --attach --keep-subject origin | git-imap-send ############### Git Config ###### Global configuration # cat ~/.gitconfig [user] name = "Hagen Paul Pfeifer" email = "hagen@jauu.net" [diff] color = auto [pager] color = true [status] color = auto ###### Projektspecific configuration # cat .git/config [core] repositoryformatversion = 0 filemode = true [user] email = "project1-bugs@jauu.net" [imap] Folder = "Drafts" Tunnel = "ssh pfeifer@0xdef.net /usr/sbin/dovecot --exec-mail imap 2> /dev/null" ############### Stacked GIT # Help stg help # Repository initialisation stg init # Switch between GIT branches stg branch [] # Creating a patch stg new stg refresh # View differences stg status # haven't been saved (refresh) stg files # view modified files # Addition or deletion of files stg add [*] stg rm [*] # Stack manipulation: managing multiple patches # see the name of the topmost patch stg top # order of patches in a stack stg series stg applied stg unapplied