Skip to content

Instantly share code, notes, and snippets.

@bandwidthcrunch
Created February 14, 2013 08:41
Show Gist options
  • Save bandwidthcrunch/4951373 to your computer and use it in GitHub Desktop.
Save bandwidthcrunch/4951373 to your computer and use it in GitHub Desktop.
git cheatsheet
Downloading the latest stable tree
First, checkout the stable kernel git repository:
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
cd linux-stable
Next, find the latest stable kernel tag by running
git tag -l | less
Find the latest stable kernel by looking for the largest vX.Y.Z values. For example, use the v3.1 tag over the v3.0.46 tag. If v3.1.1 is available, use that instead of v3.1. The kernel tags that end with -rcX are release candidate kernels, not stable kernels.
Now checkout the code associated with that kernel with the command
git checkout -b stable tag
Where tag is the latest vX.Y.Z tag you found.
Downloading the latest -rc tree
First, check out Linus' tree:
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux.git
To apply the patch, go to the base kernel directory and run
git am patchfile
Where patchfile is the file you saved. If patch fails, you can run:
git am --abort
git reset --hard HEAD
git am -3 patchfile
Reverting a patch
If a maintainer wants you to revert a patch you have applied, and try a different patch, you can use git to reset the history to the point before the patch was applied.
If git log shows the patch to be removed is the first log entry, you can run
git reset --hard HEAD^
If you need to revert several patches, you can use git log to find the commit ID of the first commit before those patches. For instance, say you have applied two patches to the stable tree 3.4.17, and you want to revert those patches. git log will look like this:
$ git log --pretty=oneline --abbrev-commit
8901234 Testing patch 2
1234567 Testing patch 1
5390967 Linux 3.4.17
1f94bd4 drm/i915: no lvds quirk for Zotac ZDBOX SD ID12/ID13
0187c24 x86, mm: Use memblock memory loop instead of e820_RAM
a0419ca staging: comedi: amplc_pc236: fix invalid register access during detach
To reset your tree to 3.4.17, you can run:
git reset --hard 5390967
If you look at the commits with gitk you will notice that the 3.4.17 commit is also tagged as v3.4.17. You can reset by tag as well:
git reset --hard v3.4.17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment