Some favorite git commands
Sep 2, 2013Working on HTTPS Everywhere, an open source project with dozens of contributors, has sharpened my git vocabulary immensely. I figured I’d list a few lesser-known commands that I like:
- git log _-pretty=oneline -n
–abbrev-commit -G_: This shows the latest commits in oneline format with shortened commit hashes that added or removed lines matching . The git pickaxe options (-S, -G) are super useful for searching git commit contents instead of just the commit messages. - git checkout
<path/to/file>; git reset; git add -p; git commit : This is almost always less preferable to git cherry-pick, but it is useful when you want only certain hunks of commits to certain files in. git checkout copies the file from the other branch into the current branch and stages the changes for commit. git reset unstages them so we can select the parts we want to add to our branch on a hunk-by-hunk basis using git add -p. Unfortunately this doesn’t preserve authorship of the changes from . - git update hooks: We decided that it would be great if the HTTPS Everywhere git server could automatically reject commits that broke the build. It turns out that this is possible using a server-side git update hook, which runs just before updating the refs on the git server. The strategy is to create a temporary copy of the remote with the newly pushed changes, do a test build, and reject the changes if the build fails. See here for an example of this in HTTPS Everywhere adapted from a Stack Overflow answer.
More to come!