git notes 1

Git notes 1:
===========================================

Git pages

$ echo “foobar.com” > CNAME
$ git commit && git push
Subdomain (like www):

CNAME => username.github.io
Apex domains:

ALIAS => username.github.io
Apex domains (alternative):

A => 192.30.252.153, 192.30.252.154

URLs

github.com/:userrepo/blame/:branch/:path
github.com/:userrepo/commit/:commit

git log –pretty=”format: …”

%H – commit hash
%h – commit hash, abbrew
%T – tree hash
%T – tree hash, abbrev
%P – parent hash
%p – parent hash, abbrew
%an – author
%aN – author, respecting mailmap
%ae – author email
%aE – author email, respending mailmap
%aD – date (rfc2882)
%ar – date (relative)
%at – date (unix timestamp)
%ai – date (iso8601)
%cn – committer name
%cN – committer name
%ce – committer email
%cE – committer email
%cd – committer date
%cD – committer date
%cr
%ct
%ci
%cd – ref names
%e – econding
%s – commit subject
%f – commit subject, filename style
%b – commit body
Refs

HEAD^ # 1 commit before head
HEAD^^ # 2 commits before head
HEAD~5 # 5 commits before head
Branches

# create a new branch
git checkout -b $branchname
git push origin $branchname –set-upstream

# get a remote branch
git fetch origin
git checkout –track origin/$branchname

# delete local remote-tracking branches (lol)
git remote prune origin

# list merged branches
git branch -a –merged

# delete remote branch
git push origin :$branchname

# create a new branch
git checkout -b $branchname
git push origin $branchname –set-upstream

# get a remote branch
git fetch origin
git checkout –track origin/$branchname

# delete local remote-tracking branches (lol)
git remote prune origin

# list merged branches
git branch -a –merged

# delete remote branch
git push origin :$branchname

# get current sha1 (?)
git show-ref HEAD -s

Submodules

# Import .gitmodules
git submodule init

# Clone missing submodules, and checkout commits
git submodule update –init –recursive

# Update remote URLs in .gitmodules
# (Use when you changed remotes in submodules)
git submodule sync
Diff

Diff with stats

git diff –stat
app/a.txt | 2 +-
app/b.txt | 8 ++—-
2 files changed, 10 insertions(+), 84 deletions(-)
Just filenames

git diff –summary

Git revisions
Revision ranges

git log master # branch
git log origin/master # branch, remote
git log v1.0.0 # tag

git log master develop

git log v2.0..master # reachable from *master* but not *v2.0*
git log v2.0…master # reachable from *master* and *v2.0*, but not both
Commits

dae68e1 sha1

References

HEAD reference
master branch
v1.0.0 tag
origin/master aka, refs/remotes/origin/master
heads/master aka, refs/heads/master

Searching back

master@{yesterday} also 1 day ago, etc
master@{2} 2nd prior value
master@{push} where master would push to
master^ parent commit
master^2 2nd parent, eg, what it merged
master~5 5 parents back
master^0 this commit; disambiguates from tags
v0.99.8^{tag} can be commit, tag, tree, object
v0.99.8^{} defaults to {tag}
:/fix bug searches commit messages

Other

HEAD:README …
0:README (0 to 3) …

Basic filters

git log
-n, –max-count=2
–skip=2

–since=”1 week ago”
–until=”yesterday”

–author=”Rico”
–committer=”Rico”
Search

git log
–grep=”Merge pull request” # in commit messages
-S”console.log” # in code
-G”foo.*” # in code (regex)

–invert-grep
–all-match # AND in multi –grep
Limiting

git log
–merges
–no-merges

–first-parent # no stuff from merged branches

–branches=”feature/*”
–tags=”v*”
–remotes=”origin”
Simplification

git log — app/file.rb # only file
–simplify-by-decoration # tags and branches
Ordering

–date-order
–author-date-order
–topo-order # “smart” ordering
–reverse
Formatting

–pretty=”…” # see man git-log / PRETTY FORMATS
–abbrev-commit
–oneline
–graph
Git Extras
Git-flow

$ git feature myfeature
switched to branch ‘feature/rofl’

$ …
$ git checkout develop
$ git feature finish myfeature
merging ‘feature/rofl’ into develop
deleted branch ‘feature/rofl’
Also git-bug and git-refactor.

Branches

$ git delete-merged-branches
# hint: do `git remote prune origin` after

$ git create-branch development
$ git delete-branch development

$ git fresh-branch gh-pages
Inspecting

$ git summary # repo age, commits, active days, etc
$ git impact # impact graph
$ git effort # commits per file
Github

$ git fork strongloop/express
Tags

$ git release v1.0.0 # commit, tag, push-tags
$ git delete-tag v1.0.0
Conveniences

$ git ignore “*.log”
Locking

Assumes that changes will not be committed.

$ git lock config/database.yml
$ git unlock config/database.yml
Etc

$ git obliterate secret.yml # remove all references to it
References
https://github.com/visionmedia/git-extras

Travis-ci
Create an OAuth token and encrypt it

Use https://github.com/settings/tokens/new

# via ruby
gem install travis
travis encrypt -r user/repo GITHUB_TOKEN=[the token here]
Make it run the deploy script on deploy

# .travis.yml
script:
– bash ./scripts/deploy-to-gh-pages.sh
env:
global:
– GITHUB_REPO: “user/repo”
– secure: “nlnXJW/imf/w…” # <– from travis-encrypt
Write deployer

Create the file scripts/deploy-to-gh-pages.sh

#!/bin/bash

set -o errexit

rm -rf public
mkdir public

# config
git config –global user.email “nobody@nobody.org”
git config –global user.name “Travis CI”

# build (CHANGE THIS)
make

# deploy
cd public
git init
git add .
git commit -m “Deploy to Github Pages”
git push –force –quiet “https://${GITHUB_TOKEN}@$github.com/${GITHUB_REPO}.git” master:gh-pages > /dev/null 2>&1
From Ractive, this might be useful in certain cases:

if [ “$TRAVIS_PULL_REQUEST” != “false” -o “$TRAVIS_BRANCH” != “master” ]; then exit 0; fi

assyrian technical blog