SaltyCrane Blog — Notes on JavaScript and web development

git notes

How to get the tag associated with a specific git revision

$ git describe --tags 5c70d1a15a4637a2057b1464c54820629e78cd05

How to show the tracked branches from the remote "origin"

$ git remote show origin 

How to find renames

$ git log --name-only --follow --all -- filename 

How to remove all local tags


$ git tag -l | xargs git tag -d 

How to detach a subdirectory into separate Git repository

Note I did not want any tags or branches in the new repository. From

$ git clone --no-hardlinks /XYZ /ABC
$ cd /ABC
$ git remote rm origin
$ git tag -l | xargs git tag -d
$ git filter-branch --subdirectory-filter ABC HEAD
$ git reset --hard
$ rm -rf .git/refs/original/
$ git reflog expire --expire=now --all
$ git gc --aggressive --prune=now 

How to convert a Mercurial repo to git


$ git clone git://
$ mkdir new_git_repo
$ cd new_git_repo
$ git init
$ /path/to/ -r /path/to/hg_repo
$ git checkout HEAD

How to create a patch for a single commit


$ git format-patch -1 01434ee4fe056e384decbf2d398cccafe53120f2 --stdout > mypatch 

How to break up a previous commit into more than one commit

git rebase -i will do it.

To split apart your most recent commit, then:

$ git reset HEAD~

Now commit the pieces individually in the usual way, producing as many commits as you need.

If it was farther back in the tree, then

$ git rebase -i HEAD~3

where 3 is how many commits back it is.

When you get the rebase edit screen, find the commit you want to break apart. At the beginning of that line, replace "pick" with "edit". Save the buffer and exit. Rebase will now stop just after the commit you want to edit. Then:

$ git reset HEAD~

Commit the pieces individually in the usual way, producing as many commits as you need, then

$ git rebase --continue

How to replace the master branch with another branch

git checkout seotweaks
git merge -s ours master
git checkout master
git merge seotweaks

Commit message when I did this at work:

Replace old "master" with "dp.2013.r21" using

    git checkout dp.2013.r21
    git merge -e -s ours master (that's where I am right now)
    git checkout master
    git merge dp.2013.r21
    git push origin master

    git branch -D dp.2013.r21
    git checkout dp.2013.r21

The automatically generated merge message:
Merge branch 'master' into dp.2013.r21

How to exclude files from "git diff"

There are 2 options:

  1. Use .gitattributes as described here:
  2. Use new pathspec magic described here: Example:
    $ git diff --stat=120,120 HEAD~10 | wc -l
    $ git diff --stat=120,120 HEAD~10 -- '*/_assets/built/*' 'tests/robot/*' | wc -l
    $ git diff --stat=120,120 HEAD~10 -- . ':!*/_assets/built/*' ':!tests/robot/*' | wc -l
    (The count is off by one because there is an extra line in the output.) I will use this option because I can use it with icdiff which shows whitespace changes.