git notes main page | gitolite main page | license

IMPORTANT NOTE: although this page has a "gitolite.com" URL, this is not about gitolite. That's just an artifact of "sitaramc.github.com" being translated to "gitolite.com" and so ALL my git related stuff gets carried over. Gitolite documentation has another /gitolite in the URL, so you can tell. My apologies for this confusion.

advanced tips

backing up work in progress

This is how you can backup everything on your local repo that is not already on one of your remotes, including all untracked files not covered by the ignore mechanism. I use a script based on this to save my work to a remote server at regular intervals, in case of a disaster (hardware failure, etc) on the regular desktop.

# sort of like stash; untracked files also saved
git commit --allow-empty -m wip-index-state
git add -A && git commit --allow-empty -m wip-worktree-state

# make a temp branch (FIXME: should we do this first?)
git branch wip-backup ||
    die 'could not create wip-backup branch; aborting';

# unstash
git reset --mixed HEAD^
git reset --soft HEAD^

# create the bundle and remove the temp branch
git bundle create /tmp/sos.bdl --all --not --remotes
git branch -D wip-backup

# copy that file wherever you want, however you want...
rsync /tmp/sos.bdl bkphost:   # or scp, or whatever

conflicts on pull/merge

log pickaxe and blame

what are all these “HEAD”s?

garbage collection

NOTE: this section is old; I have not looked at it with respect to recent git versions.

recovering a dropped stash:

the GUI way

You dropped a stash that was created recently, and now you want to recover it. As long as you did not do a garbage collection in between, this should work:

gitk $(git fsck | grep commit | cut -f3 -d' ') --since='1 week ago'

The part within the parenthesis finds all unreachable commit objects and returns their hashes. If you never did a garbage collect there might be too many false positives so the --since clause (which you can adjust to whatever you want of course; mine is just an example) limits the display to commits created recently.

A “stash” has a very recognisable, triangular, shape in the commit DAG, and with gitk you can visually find stashes really fast. For me, this is the kind of task that calls out for a GUI – infrequently required, no conceivable need to automate, and containing data that stands out visually.

the command line way

Writing something longer than that for a problem that occurs once in a blue moon is not my style (very low ROI!), but doener gave me this:

git fsck --unreachable | grep commit | cut -d\  -f3 |
xargs git log --no-walk --merges --grep='^\(WIP on \|On \)\((no branch)\|[^ ]\+\):'

I knew about --merges but not --no-walk, and I anticipate using it a lot more in future :-)