git

Squash git commits when merging

Today I’ve been fighting to get our test suite to run against a newly delivered Oracle 12 database. Of course, that didn’t work out of the box, so there was some debugging, trial-and-error, and cursing involved. Finally, I managed to get the build back up and running. Yay! The commit history for this pull request was horrible and some would call it unprofessional, looking at the various commit messages written in anger.

Rails: Prevent Accidental Debugging Commits

Your Rails app has grown over time, multiple developers have worked on the code and you are about to make a small change in the code. Unfortunately this change applies to code that allows you to view a financial overview of last year’s data. It’s legally not allowed to expose the current year’s data, but the change you need to make applies only to 2014. We should shift time to 2015.

GPG Sign Your Git Commits

I have written and talked before about GPG and the need for trust on the internet. Getting started with GPG and using it on a daily basis is, when you’re using the right tools, not all that hard, but still quite technical. Today Google announced they are working on a Chrome extention to enable end-to-end encryption using OpenPGP. As a developer, I do more than dispatching emails all day. On occasion I write code.

Deploying with git-deploy

I’ve blogged before about deploying Rails applications. Normally I opt for using capistrano, as it provides all the features I need and is pretty easy to customize if needed. One of my previous strategies was to use capistrano to checkout a branch on a remote server, and git fetch that branch upon a new deployment. The problem with capistrano, however, is that it can be quite slow from time to time.

Review commits in your feature branch

Github pull requests are awesome, but you can’t use them all the time, mostly when working on code not hosted at github. The following snippet makes it easy to see the commits in your current (head) branch that are not yet in the base branch. To see what commits are made in your current feature branch, but which have not been merged into develop yet: $ gpr develop * 5246248 <ariejan@ariejan.

Binary debugging with git bisect

Part of resolving a bug is finding where and when that bug was introduced into your code. Not so much for blaming a specific person, but more for an understanding of how and maybe why the bug was introduced; and more over which versions of your app are affected. Most of the time the bug was recently introduced and your CI notified you that stuff has been broken. In order to find out when, how and by whom the build was broken, you’ll have to dig into your git history and run your specs to see if they pass or not.

Migrate git repositories

Sometimes you have to move your git repository to another host. In this case I want to move a privately hosted git repository to a brand spanking new github repository. These are four easy steps to get that done: git clone --bare git@yourserver.com:project.git cd project.git git push --mirror git@github.com:ariejan/project.git cd .. && rm -rf project.git That’s it. Don’t forget to update the remote of your working copy accordingly: git remote set-url origin git@github.

Git: Interactive Revert

I recently made a commit in a project that, mistakenly, included changes to db/schema.rb. My local schema was out of date and this could cause trouble for the others in my team. Luckily we use a successful git branching model so my changes were still up for review by the team. The change I made was part of larger commit. But all I wanted was to revert serveral chunks from db/schema.

Move your latest commits to a separate branch

The situation is pretty straightforward. You have been making commits for that new feature in your master branch. Naughty you! Let’s assume you want to have this: A - B - (C) - D - E - F C was the last commit you pulled from origin and D, E and F are commits you just made but should have been in their own branch. This is what you wanted:

Removing untracked files and directories with git

I just tried writing some new code, but it was no success. This happens, but it left me with a working copy littered with new and changed files. # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: config/routes.rb # # Untracked files: # (use "git add <file>.