Tag: Git

Code Tips

Git Error : (does not point to a valid object)

A friend of mine IMed me the other day to ask if I had ever seen an error like the one below:

error: unable to find e291a84831b445ba982539cc63a418126f0b5364
error: refs/heads/master does not point to a valid object!
fatal: Couldn't find remote ref master
fatal: The remote end hung up unexpectedly

I had not, but it seemed plain enough. It appeared that the head of the master branch was pointing to a commit that didn’t actually exist in the repository. I don’t know for sure how this happened, but my friend’s team suspected a disrupted internet connection on push as one theory.

I Googled the error and found suggestions like “make a new remote” and “clone to a new branch, push, delete master, rename new branch”. This seemed like just too much work. There had to be an easier solution.

I was unable to clone the remote to my own machine (I got that same error on trying) and the team was in another state, so – short of a screensharing session – I couldn’t easily work with them on the problem.

I had the developer who had done the last known valid commit before this error send me the most recent 5 items output from the “git log” command and got the following (edited for privacy):

commit b65f24a64e78b38d193aa545d7b184fe26330a4c
Author: Joe Developer <joed@somewhere.com>
Date:   Fri Jul 27 10:05:53 2012 -0400

    Moved foo.jar to libs folder

commit 32b15424509881760667a77b615cc91e8e31afb9
Author: Joe Developer <joed@somewhere.com>
Date:   Thu Jul 26 21:45:46 2012 -0400

    Load swf files

commit bfac8d86c20ebbcac22af4e599e5815b0586f3d0
Author: Joe Developer <joed@somewhere.com>
Date:   Thu Jul 26 19:18:25 2012 -0400

    Navigation bug fixes

commit 60c5ff87435861157e56d948e09c63ad2f4db520
Author: Jane Developer <janed@somewhere.com>
Date:   Thu Jul 26 15:52:36 2012 -0400

    post merge

commit 1a97d137a51c6cd34825e4c9bc705620dfff7712
Author: Jane Developer <janed@somewhere.com>
Date:   Thu Jul 26 15:24:40 2012 -0400

    initial commit

Because Git is based in the file system, I could literally navigate to the remote file system and go to the ProjectName.git folder and into the refs/heads/ folder and find the master file (no extension). Inside was one string, the offending e291a84831b445ba982539cc63a418126f0b5364. I just replaced that string with the hash of the latest valid commit – b65f24a64e78b38d193aa545d7b184fe26330a4c – and then saved.

After that, I could clone the repo and the developers could pull, merge, and push their own changes. They were using DropBox in this instance as a “poor man’s remote” and upon further reflection, I have to wonder if that is what caused the conflict. Perhaps there was a problem with DropBox syncing all of the files and maybe a race condition at some point that resulted in a corruption? I know DropBox isn’t a perfect “remote server” solution, but a lot of people use it for certain circumstances, so this might be something to look out for.

If anyone else has seen this error and has a better fix than the one described here, then please leave a comment and let me know.

Conferences

My Pittsburgh Code Camp 2011.1 Slides and Links

I just completed my talk, “Git for .Net Developers” and – as promised – here are my slides. I’ve got them up on SlideShare and also a straight Powerpoint Download.

Links pulled out of the Powerpoint

Download msysgit (I recommend downloading Portable Git)
Git Extensions
GitHub’s Setup Help
Git Immersion
Why Git is Better Than X
Best Git Cheatsheet Ever

If you were there, please Rate My Talk

A question came up about tools that can help you migrate, or use as a bridge.

SVN-Git Bridge (Read this Stack Overflow Q&A (SVN-Git is included in certain downloads of msysgit)
TFS-Git Bridge

Conferences

Speaking at Pittsburgh Code Camp 2011.1

Last Saturday, I got the news that I’ll be speaking at the Pittsburgh Code Camp at Robert Morris University in Pittsburgh, PA. Being from the area, it is kind of exciting to have the first place that I get to present be my hometown.

My talk is called “Git for .Net Developers” and my preparation is already well underway. I’m really excited about sharing this topic with others. At first, I was a little nervous about filling up the entire hour and fifteen minutes, but now I’m wondering if I’ll need to cut some things :). I plan on running through this about a million times before April 30, so I’m sure I’ll figure it out!

Here is a copy of the schedule as it is laid out at the time of this post (click for larger version):
2011 Pittsburgh Code Camp Schedule

I’d really like to get into presenting to the community in a big way, so I’m definitely excited for both this opportunity and for the opportunity to get feedback so that I can be the best speaker that I can be. If you are anywhere near Pittsburgh and are free on Saturday, April 30th, you should definitely come out to the Code Camp. Use this link and sign up. It is free, but they want your registration so that they are sure to have enough space and enough lunch! I hope to see you there.

Git

Git > Charlie Sheen

In my last post, I talked about being shown something that just blew my mind about the power of branches in Git and as I understood what was happening, this little experiment got me to REALLY understand just how changes are tracked in Git and how branching and merging works in Git, as well.

To begin with, if you don’t understand Git at all, or are really confused after reading this post, I recommend going to Git Immersion. I’ve found no better tutorial and it got me from 0 to successfully using the product pretty quickly. You have to have Git installed and configured if you want to follow along with my examples in this post.

To start out, navigate to an empty directory. I opened my Powershell console and from my root typed these three commands, one at a time.

mkdir ninja
cd ninja
git init

I then saw the following:
Create Ninja Git Repo

Let’s create a text file in our directory containing the contents of the directory.

ls > DirectoryContents.txt

Now our directory looks like this:
Create Directory Contents File

Our next step is to add the file to be tracked by Git and commit it. I typed in these commands, one at a time

git add .
git commit -m 'Created Directory Contents File'
git status

My output looked like this
Adding the file to Git

Now we are all set. I plan on doing some work on a feature here, so I’m going to branch this repo so that I can make changes in isolation and then merge back.

Type in

git branch pirate
git branch

The first statement creates a branch of the repository called pirate and then calling the branch command by itself lists the branches you have. You’ll notice that master is colored and has an asterisk (*) next to it, indicating that it is the branch that I’m working in.
Create the Pirate Branch

Now if you issue these commands, you will see that we have switched ourselves to the pirate branch to do our work.

git checkout pirate
git branch

Switch to the Pirate Branch

Now let’s delete the existing file and create a new one and look at our directory.

del DirectoryContents.txt
ls > PirateFile.txt

Current Pirate Repo Directory

Okay, we’ve been having fun, but now we need to make an emergency fix back on the original file in the original branch. Let’s commit our pirate changes and switch back to master. If we just issue these commands we see that our directory is really just as we left it the entire time.

git add .
git rm DirectoryContents.txt
git commit -m 'out with the old, in with the new'
git checkout master

Directory Contents is on Master

Now, let’s visit the pirate branch again.

git checkout pirate

Back in Pirate Repo

To me, that really just threw a switch and I began to understand how Git was tracking individual changes one by one and could “play them back” against a repo to perfectly put you wherever you needed to be at any point in time. In TFS and SVN, you branch to another directory, which if you have a web app, causes a lot of IIS configuration changes. Even if you don’t do web apps, if you branch per feature, you are going to have a lot of “spare” directories lying around. That just makes my OCD hurt.

I know that SVN has the “switch” command, that takes the branch from the central repo (which is in a different directory) and puts it in your current directory structure. That certainly behaves a lot like Git branching, but when you add in Git’s other features, I’ll definitely have to choose Git over SVN as well as TFS.

Hopefully I’ve explained this well and you get exactly how powerful and simple this is and how Git can really alter your relationship with source control. My initial fears were that Git would get in the way (because of the command line stuff, etc), but instead Git has made source control get out of my way and just let me focus on dominating the codebase 😉

Git

Get Your Git On

Can You Dig Git? (from http://blog.aquabirdconsulting.com/?p=262)As I stated in my 2011 technology resolutions, I really wanted to make an effort to learn Git this year. I started with learning some Git Immersion, which I documented as well.

Well, since I like to go big or go home, I decided to start using Git at work full time. We have a big project that we started last week that requires us to branch our code and maintain this “catastrophically different” branch and our “hotfix” branch so that we can still get any bug fixes or emergency features to production in the meantime.

As many of you who have worked with it know, doing a long running branch in TFS (our old VCS) SUCKS hard. The merge would have not been fun. On top of that, switching between the branches to perform bug fixes wouldn’t have been fun either. We would have had to maintain separate directories, which means remapping local IIS routes for testing, etc. Disaster city.

However, when I saw that when you jump between branches in Git and your directories and files just “magically” transform into what you expect them to be in place, I was sold. We had to have that wizardry. Since Chris already knows him some Git, I felt like I was working with a safety net, so we went for it.

Chris used spraints’ git-tfs to migrate our TFS source (with history!) into Git so that we literally lost nothing in the transition. One note of warning was that it had trouble with a very large binary file that we had checked into source due to some memory constraints. We hard deleted it from TFS and the migration went much more smoothly from that point, though Chris still had to work some magic. Maybe he’ll blog it???

We’re officially about a week and a half in with Git and we actually haven’t had as many problems as I had feared. We had a little scare last week when a deployment went wrong, but it turned out that we ended up with a weird WCF issue that forced us to need to reproxy in every project that consumed that service. I had worried that Git had messed up our very large file, but we did some experiments and proved that it behaved exactly as it was supposed to. (Good thing, too, or that “three” I shot in pulling the trigger on the Git switch might have cost me an earful.)

Next blog, I’ll show everyone what “magic” really impressed me with Git. People who are old had at Git will maybe scoff at what I thought was mind-blowing, but I imagine some VSS/TFS-only users may have their face melt off and children will weep over their exploded bodies. (update: I’ve blogged the example here)