(how to) create a patch with GIT

I admit this is probably not an ideal setup, but I’m running apps, that I checkout and update via GIT. If the publisher issues an update, all I have to do is run git pull (or switch to tag or branch).
Another upside is that I can track any changes I made to the code – a technique called monkey-patching. The changes are usually needed to adapt the software (PHP, Ruby, Java) to my particular needs. I therefore makes little sense to contribute those changes back to the (open source) project.

If you want to apply those changes to a different installation or re-apply after an (software-internal) update, you need a way to replicate the changes. A good way for this are patches – one or more files containing only the changes made to particular files.

Here’s the short version for creating a patch, found at https://ariejan.net/2009/10/26/how-to-create-and-apply-a-patch-with-git/:

  1. first create a new branch (yes, this is really necessary)
    • git checkout -b my_patch_branch_name
  2. make your changes (or copy the changed files over)
  3. commit your changes
  4. create the patch (save the changes in the new branch compared to the master branch)
    1. git format-patch master –stdout > fix_empty_poster.patch
  5. done.

To apply the patch, run the following:

  • git am –signoff < fix_empty_poster.patch

This actually applies the patch and signs off on it, which means the changes are commited to the branch (most likely main) your current copy is on. Check “git log” and you’ll find the applied patch in the comments.

That’s it – just a short procedure.

PS: To switch your current working copy back to the master branch, run “git checkout master”

edit SASS-templates in VIM

The problem is simple – and the answer should be as well. But it turns out, that some things in computer science are not as they might seem. 😉

I wanted to edit a SASS-file (-> http://sass-lang.com) for a rails project. The source-file is required to have space-indenting with 2 spaces for every indentation. I caught myself using the tab key to indent everything, but then the parser simply gave me error-messages. 😦

So I had to find a way to make vim interpret the tab key as 2 spaces – easier said then done. 😉
A more sophisticated list of commands for vim can be found here.

The commands I used to get the results I needed were:

set expandtab
set softtabstop=2
set shiftwidth=2

A note at the end: This only works for vim – not for vi!

So if you’re using vim – have fun or at least more success with this! 😉