Tag Archives: Git

Changing filename case in Git

I have a file named ‘filter.php’ and I renamed it to ‘Filter.php’, but Git doesn’t notice this. Instead I needed to do something like this:

git mv filter.php filter.php2
git mv filter.php2 Filter.php

It looks stupid, but it works like a charm!

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])

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 https://github.com/janmoesen/forkcms.git
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 github.com 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.

Git diff not very clear

From time to time I have to mess in code that I haven’t written. Some of those other developers don’t trim whitespaces or blank lines which makes my git diff look kinda messy. There’s a solution for this.

‘git diff’

‘git diff –ignore-space-change’