Monthly Archives: June 2011

You are browsing the site archives by month.

Removing a git alias

I had an issue trying to remove a git alias I made. You can remove it by deleting that line from the configuration file, but I wanted to know how to do it using the git config command.

git config --global --unset alias.myAlias

When did I introduce a certain string?

Today I needed to know when the string ‘2.1.0‘ was introduced in my git repository. There’s a nifty way in git log you can use for this.

git log -S ’2.1.0′

Tar changed files between 2 commits

Replace [hash] with the hash of the commit. This defaults to all the changed files between the hash and HEAD.

tar zcvf “$(date +’%Y-%m-%d-%H-%M-%S’)-xmple.tgz” $(git diff –name-only [hash])

You can also update the commit range by using two hashes separated with 2 dots.

tar zcvf “$(date +’%Y-%m-%d-%H-%M’)-xmple.tgz” $(git diff –name-only [hash]..[hash2])

SSH completion

I hate it when I need to type the entire host I want to connect to. So I’ve added this to my ~/.bash_profile which autocompletes the ssh command based on my ~/.ssh/config

complete -W “$(awk ‘/^\s*Host\s*/ { sub(/^\s*Host /, “”); print; }’ ~/.ssh/config)” ssh

Thanks to @janmoesen for fixing the error.

MySQL configuration file

Place the configuration file ‘my.cnf’ in your home directory.

I no longer need to type ‘mysql -uroot -proot …’ to connect to my local databases. You can also set some other options such as the default character set which defaulted to latin1 in my case. I don’t like latin1, but I also don’t like typing this over and over when connection to a database.

Let mysqldump help you!

I used to dump mysql data using PHPMyAdmin. People should get kicked in the nuts for doing that.

Dumping a (remote) database:

mysqldump -uroot -proot – my_database > Desktop/dump.sql

Restoring a database:

mysql -uroot -proot my_database < Desktop/dump.sql

Disclaimer: I know that it’s stupid to set the password in the command, but this is just for the example. /cc @adeepersilence

Git checking out a remote branch

I need to checkout remote branches from other repo’s quite a lot. Mostly these repo’s are forks from the repo that I’m on. An example of what I do to make this go smooth without having to create a local branch (which is based on the master).

git remote add janmoesen
git fetch janmoesen
git checkout -b janneman janmoesen/rewrite-navigation-cache-file

I now have a new branch ‘janneman‘ that does not contain any nasty merge commits because I checked it out in one step.

ps: I used to follow the steps on to get a branch from another repo, but they make you create a branch locally before pulling from that remote branch. If you do so, you will get a merge commit and I don’t like that.