in

CodePrairie .NET

South Dakota .NET User Group

chrisortman

Can your VCS do this?

Here's an interesting scenario I just ran into that makes me glad I am using git.

I'm in the middle of working on a project which uses the same database for testing as development (not my idea) and I wanted to change the way that navigation on one of the pages works. This involves changes to the code as well as to a stored procedure. So I begin work like this

git checkout -b experiments/new-navigation main

Which will create a new branch for me to do my work in. Once the work is done I notify my testers to see what they think of the proposed change.

While they are reviewing I want to be able to work on another feature, so I start:

git checkout -b work/add-update-support main

Which creates a new branch based on the main (which doesn't have any of the navigation changes I just did).

The problem I'm going to have is that the database is using a version of the stored procedure I changed, but the change is incompatible with version of the code I have.

What would you do? I'm not sure what I would do with subversion, probably copy and paste some hacks and leave TODO: markers by them. I'm using git though so I have a better way.

Conceptually what I want is to go back in time and pretend I had made all the changes for update but started with navigation instead of main. Git has just the thing to do this and it is called rebase.

git rebase --onto experiments/new-navigation main work/add-update-support

So what happened after I ran this command?

Here's a helpful graphic (excuse my poor image editing skills)

The first diagram in my image shows what my working copy looked like before the rebase, and the second picture shows it after. As you can see I've gone back in time and made git think that my work/add-update-support started from a different base.

Now I can continue to work on the update feature in the work/add-update-support branch. When I'm all done I have 2 options. If people like the navigation I can merge the work/add-update-support branch back into main, or if they don't I can rebase again and transplant the branch back onto main ala:

git rebase --onto main experiments/new-navigation work/add-update-support 

 

Technorati tags:

Comments

No Comments

Leave a Comment

(required)
(optional)
(required)
Add
Powered by Community Server (Commercial Edition), by Telligent Systems