Thursday, 15 July 2010

Undoing early morning/late night stupidity with Mercurial

So laaaate this morning (around 3am) I was putting some finishing touches to a refactor I was working on for my own project and I came to use tortoiseHg to look at the status of my files. Loads were selected for modification, many for addition and several that I’d removed were ready for removal.

Unfortunately for me with all these changes selected in TortoiseHG’s file status dialog I managed to hit the “Forget” button on the toolbar. Immediately my additions went back to unknown status and all my modifications were marked as removals (which I would assume is a revert not actually a remove!).

Anyway, completely NOT what I was looking for, so now I needed to work out how to get my files added back into the repository and how to make sure my modifications would be taken into account. You can’t just click on the modification that is now a removal in Tortoise and select add again – it doesn’t allow it, not sure why, so it’s time to go back to the command line.

First off, dealing with the adds that have now been forgotten is simple, we can just re-run a hg add and they will get pulled back in.

hg add

Dealing with the modifies which are now removals is more difficult. You can use hg add to add each individual file in one by one, but this is a massive pain in the ass, so instead use come clever old skool dos;

for /f %f in ('hg stat -rn') do hg add %f

the /f says we’re looking to process a file list, each file being pushed into %f. The command to execute is in the brackets and quotes (-rn lists only things tagged for removal and skips outputing the initial status character). The do command then specifies what to do for each one of the files returned… in this case, hg add it. And voila, problem solved and I can go to bed with my repository still in order….

No comments:

Post a comment