SVN revert equal in Git

Using git, coming from SVN and want to revert changes on a file? In SVN it used to be:

svn revert filename

Well revert in git isn’t what you want to do in this case. Due to it’s local repository you have to think a bit different here. When checking out you get the latest committed version from your local repository, so what you actually have to do is the following:

git checkout filename

Now you have the equivalent to the gold old revert.

git svn status

Working with git-svn and need to know what your svn status would look like? Well within two lines you could be there. First make sure that your remotes/git-svn is up to date:

git svn fetch

Now you can a diff over that branch:

git diff --name-status remotes/git-svn

You should now see your standard diff. In case this didn’t work or your not sure where your default branch is lying, enter the command:

git branch -a

This will show you all your local and remotely tracked branches. Which looked in my case like this:


* master
remotes/git-svn

Ruby check if string is null or empty

Coming from C# I liked the Frameworks implemented option to check in one go if a given string is null or empty.

Now in Ruby the string class has the method empty? which checks just that i.e. null or empty. But due to the dynamic nature of Ruby one has to tell the interpreter that one would like to have the object as string before you can access the method.

The following code is an example on how it’s done:

some_string.to_s.empty?

Ruby print number with leading zeros

When needing to print out a number with leading 0 the easiest way I found was:

some_number = 3

result_string = "%02d" % some_number # => "03"

After the percent symbol the 2 tells ruby the minimal length of the number and the 0 tells it what to put in if the length is not met (default is a whitespace i.e. space).

Should a larger number be passed to the output format for example 1234, the output will be “1234”, so it will not be shortened.