Git: Move changesets into feature branch from master and reset

After having used SVN for over 5 years it is hard getting used to the Git work flow. Once in a while code is committed to the master branch that should have been committed to a feature branch.

Create feature branch

The first thing to do is create the branch that contains the feature you were working on and push it to origin:

git branch <feature-branch>
git push origin <feature-branch>

Temporarily set the remote HEAD to something else than master, otherwise you will not be able to delete it.

git remote set-head origin <feature-branch>

The next step is to delete your master branch on your remote repository. If you use Atlassian Stash you should first set the default branch to some other branch. This can be configured under Repository>Settings>Repository Details.

Reset your local and remote master branch

Now delete your master branch on your remote repository:

git push <remote> :master

The next step is to reset your local master to the point you wish to reset to, the point before you started working on the feature you’d like to branch out.

git reset --hard <commit-hash>

The master in your local repository should be pointing to the correct changeset. Now push this new master branch to your remote repository.

git push <remote> master

Now you can set the remote HEAD back to the master branch.

git remote set-head origin master

The last step if you use Atlassian Stash is to set the default branch to master again.

Image.NineGrid for WPF

Microsoft added a new property to the Image control in WinRT called NineGrid. This allows you to scale an image without stretching the corners of an image.

borderFor instance if you scale up the image above it would stretch ugly as you can see in the example on the right. In the example on the left you can see the result of a NineGrid stretch.example

You could do the same with a Border control and RoundedCorners set to a non-zero value. The added value of scaling this way is to create fancy handdrawn bitmap based buttons.

<Image Source="image.png" Width="200" Height="150" NineGrid="20 10">

Above is an example of how you would use the NineGrid property. This creates an single Image of size 200×150 pixels consisting of 9 slices. All corners slices will have a size of 20×10 pixels.

I have created a custom control called NineGridImage for WPF based on principle of providing a single Thickness to define the dimensions.

<local:NineGridImage Source="image.png" Width="200" Height="150" Offsets="20 10">

I have posted a Gist containing the custom control code and the theme template that goes with it on GitHub Gist. To use it place the generic.xaml file in a folder named Themes in the same project as the custom control.

Code highlighting

Just found out you can do code highlighting without plugins. Unfortunately getting code into the post dialog is horrendous. Also for some reason it does not like my greater than and less than..

MathHelper in XNA has some really handy methods which work only on specific types. Some of these such as Clamp can be implemented easily using generics:

public static T <T>(T value, T minimum, T maximum) where T : IComparable<T>
    if (value.CompareTo(minimum) < 0)
        return minimum;
    else if (value.CompareTo(maximum) > 0)
        return maximum;
        return value;