Useful Git commands – Part 4

Continuing my series of useful Git stuff, here are a few useful one-liners that can make life easier.

Recovering from bad reset

Imagine for instance that you just pulled master into your own branch but realized you should have rebased instead to avoid those pesky merge commits. Imagine also that you wanted to recover by doing a git reset --hard, but you accidentally killed some of your own commits too. It may look like you are screwed now, but all is not lost – git still knows about your commits. Use git reflog to see the commits again and merge them back as needed. If you have just killed a single commit, the easiest way to get it back is with git cherry-pick ORIG_HEAD. Handy.

Setting up proper remote tracking

You are using Arcanist in your project, and created a feature branch with arc branch, then it looks like remote tracking has been set up, but your feature branch is actually tracking master. Probably not what you want. To fix this, run git branch --set-upstream

Creating user documentation with Doxygen

Doxygen is as everybody knows, the de-facto standard for generating API documentation from source code comments. But it is also pretty great for generating user documentation, as is apparent from the Doxygen documentation itself. And with the really good Markdown support in recent versions, it is no longer necessary to write the documentation in “fake” code. Just plain Markdown works great.

There are a few gotchas, though, as I discovered when trying to generate a QT Assistant help file for the application I’m currently working on.

Continue reading

Useful git commands – part 2

Sometimes you have a project with lots of submodules that you never change yourself, but want to update occasionally. One example would be if you use Pathogen for your VIM plugins. You’d think you could use git submodule update here, and sometimes you can. But note that one of the main features of submodules is that they are locked to a particular commit. In case you want to pull in the latest changes from the remote, you need something else.

I put this alias in my .gitconfig file to solve the problem (note that this needs to be all on one line):

subup = submodule foreach 'git pull -s recursive 
-X theirs origin master'

The command will cd into each submodule, and do a forced pull overwriting any local changes you may have. Nice, right?

Useful git commands – part 1

If you are like me, you have a whole bunch of projects on your hard disk that you want to update occasionally, but don’t really work actively with. Previously I usually put an update-all.sh file in the root folder of those projects. But in most cases it is possible to use a general approach. I now do it like this:

If you pass a path to the script, it updates all subdirectories under that path, else it uses the current directory. And to make it even more convenient, you can add an alias to your .gitconfig file, like so:

pullall = !~/bin/git-pullall.sh

Now you can just use git pullall to update everything in one go. Convenient!

No more Windows for me

Well, that’s not quite true. But I have stopped using a separate Windows computer, and instead run Windows 7 in a virtual machine on my Mac. I am currently using Parallels 8.0 which works brilliantly. I have switched back and forth a bit between Parallels and VMWare Fusion. I’d say that they are quite similar functionality wise, at least for the things I use them for, which is almost exclusively to compile and debug with Visual Studio. Anyhow, the less Windows the better so I’m happy with this setup for now.

Keyboard Macros on Windows

My new job is forcing me to use Windows. Yes, it sucks a bit, but to make the best of the situation I try to set it up as similar to my Mac environment as I can. My primary editor is SublimeText 2, which is available on both platforms, so that works fine. I have set it up with all package files in Dropbox, so they are automatically shared. More on that later.

A code editor such as that relies heavily on keyboard shortcuts. And those tend to work best with an American keyboard layout. I switched over several years ago on the Mac, and use a keyboard macro program to type all the necessary national characters without having to resort to cumbersome dead key combinations and such.

So when I started using Windows, I immediately looked for a suitable program, and I can really recommend AutoHotkey (http://www.autohotkey.com). It is free, incredibly capable, as it  actually contains a full programming language and can create arbitrarily complex GUI widgets. I currently use just a small part of it, but intend to look at more use cases later. Anyhow, here’s my national characters macros. They may come in handy for someone else.

Continue reading

Print from Sublime Text 2 with this plugin

Sublime Text is a fantastic text editor, but it does not let you print. Personally, I don’t mind – I only print very seldom. But there are many entertaining discussions on the discussion forum where people who have bought the program months ago suddenly realize that it does not print, and then make as if the sky has fallen down or some such. Anyhow, Svenax to the rescue!

I started on a very simple plugin last april that just sends the document of the current view to an external command line program for printing. I naturally put the plugin on Github and promoted it a bit in the forum. Nothing much happened for a while, until I got a merge request with substantial enhancements from another Githubber. After having merged that, I took another look at the code and decided to rewrite it pretty much from scratch to clean it up and remove code duplication.

This new plugin has been submitted to Package Control, the semi-official package manager for Sublime Text extensions. Looking at the merge request queue, it seems to take about two weeks before requests get integrated. Until then you can install directly by selecting Package Control: Add Repository and adding https://github.com/svenax/SublimePrint. Happy printing!

ETA: It is now available in Package Control under the name Simple Print Function.