An occasional outlet for my thoughts on life, technology, motorcycles, backpacking, kayaking, skydiving...

Wednesday, March 9, 2011

git Oneliners

This started out as a tweet but quickly became a collection of one-liners. Some of this may be able to be accomplished with switches to regular git commands, but I can write awk faster than I can read a man page. Sad but true.

# add files to the index which `git status` lists as untracked:
git add $(git status | awk 'p==1{print $2}; /git add /{p=1}')

# remove files from the index which `git status` lists as deleted:
git rm $(git status | awk '$2=="deleted:" && p==1{print $3}; /git add\/rm /{p=1}')

# add files to the index which `git status` lists as ``Changed but not updated``/modified:
git add $(git st | awk '$2=="modified:" && 'p==1{print $3}; /git add /{p=1}')

# checkout the penultimate commit (used for stepping backwards through commit to find the introduction of a bug)
git checkout $(git log | awk '/^commit /{if(i++>0){print $2; exit}}')
# That was my first day git user approach. Now I know to use
git checkout HEAD~1
# Yes, I know about HEAD^, but because HEAD^2, HEAD^3, etc. don't work I chose tilde notation.

# create a quick git repo with 50 commits for trying out git hackery
d=/tmp/git_hack; rm -rf $d; git init $d; cd $d; for i in {1..50}; do git log | md5 >test.txt; git add .; git commit -m "commit $i"; done >/dev/null

# rebase 1 commit out of a branch
read -p "hash? " hash; git rebase --onto $hash~1 $hash HEAD; files=$(git st -s | sed '/^UU/!d;s/^UU //'); [[ -n $files ]] && (git co --theirs $files; git add $files; git rebase --continue)


About Me

My photo

Believe it or not, I've never been to jail. Not even for a night. I quit going to bars by the time my fake ID was unnecessary, and I quit hacking into businesses and governments once they started paying me.

Now I just provide for my family and try not to notice politics. I get too angry when I watch how much of my income is taken from me, how it is used, and who is doing it. For the same reason, I can't bear to acknowledge celebrities.

After high school, I went to U of K but the outdated computer engineering curriculum and the seemingly endless amounts of money to be made with my internet specific skills drew me to larger tech markets. I have worked in Silicon Valley, New York City, and have settled in Atlanta.