Posts tagged ‘git’

11 March, 2011

git: recovering from an “accidental” branch deletion

by gorthx

I’ve been experimenting more lately with git’s branching and merging capabilities. The first time I ‘git merge [branchname]’ I was a bit flustered – was it really that easy? Yes it was.

Of course, once I get confident (to use a biking analogy), I take my hands off the brakes & make some real fun mistakes while I learn to handle the higher speed.

I’m sort of a neatnik – I like to clean up old files & such (always re-discovering the inverse relationship between how long [in days] something’s been sitting around unused before I delete it and how long [in seconds] it takes someone to ask me for it afterward), so I decided to delete a branch I’d been working on that I no longer needed. I *thought* I no longer needed it.

(master) :::-->git branch -d nme_fix
error: The branch 'nme_fix' is not fully merged.
If you are sure you want to delete it, run 'git branch -D nme_fix'.

Of course I’m sure I want to delete it!

(master) :::-->git branch -D nme_fix
Deleted branch nme_fix (was ee6cb9e).

Then I go and look at my code. Ohhhh fuuuuuuuudge.

With git, it’s not gone forever. Let’s go about recovering that deleted branch.

(master) :::-->git fsck --full --no-reflogs
dangling commit 20b606fe6e3ee48d284926d8f0fe0188060eef12
dangling blob 3e22e83e45e457b716bd0d5f1cdebf3605eceb02
dangling commit ed0475437d820a0bdf86e2b729db9a3d575ff58c
dangling commit ee6cb9e81f8a8667b05427272c06db5603a67dce
dangling blob 06ff7028cb9c9e0bc93041f7931651a958e23f6d

… long list of items. Looks like I need to run `git prune` … but let’s do that *after* I recover my stuff, eh?

(master) :::-->git show ee6cb9e

This shows me the diff from that commit. (Which I piped into a file; if I am unable to easily recover my work, I can just make a few quick edits to that file & apply it as a patch.) Since I happened to have the commitid handy from the earlier confirmation message, this was just for verification. If I didn’t have it, I’d run ‘git show [commitid]’ on all of them until I found the one I wanted.

Then, git cherry-pick [commitid] to pull the changes I’d made back in:

(master) :::-->git cherry-pick ee6cb9e

Et voila, all that hard work is back.



Note the cool git prompt. I highly recommend this to everyone who’s using git. Here’s a link for a simple way to do this.

Tags: , ,
2 July, 2009

pdx.pm code sprint #1

by gorthx

Hacking on 5.10.1 was the plan…that happened for a couple of us. :)

Duke proposed a PDX.pm sprint to work on 5.10.1:
“I think if everyone learns how to

a) get a copy of the perl git repo
b) keep it in sync
c) run the perl test suite, including running a single test at a time
d) submit a small documentation patch

then we will have a great start.”

This is perfect for a first sprint: “small, solve-able tasks” that will get everyone up & running, plus have the potential to actually be productive.

Your first code sprint with a new group of people is like the first day on the job…except nobody realizes that we’re each FNGs*. It can take some time to figure out how to work together.

It’s really great if people get the stuff that’s going to take time from the code sprint out of the way beforehand. For example, cloning the perl5 git repo (step a):

:::=>git clone git://perl5.git.perl.org/perl.git

(Took me 13 minutes.)

Duke suggested some advance reading as well – how to use the repo (cd perl; perldoc pod/perlrepository.pod) (you will need to install perl-doc if you don’t have it; it was not installed on ubuntu.)

read more »

22 May, 2009

Replicating cvs’s -I option in git.

by gorthx

I’m a fairly recent convert to git, and have been moving a bunch of my coding & doc projects to it. It’s been mostly seamless, but I had one kinda tricky piece left: the daily commit (automated, of course) of any notable changes to my Cisco router & switch configs. The tricky part is handling certain lines in the configs that change each time, but aren’t necessarily of interest (for example, ntp clock-period), and I don’t want to kick off a commit if that’s all that’s changed.

cvs has this nifty -I cli option, similar to the -I option to gnu diff – it allows you to specify a regexp and the cvs diff will ignore all lines that match that regexp.

Here’s a sampling of what I had:
cvs diff
-I 'clock-period'
-I '#time'
-I 'set.spantree.port.*cost'
[filename]

(Note that you can’t have spaces in the regexp you pass to cvs.)

git doesn’t have a cli switch for this; I was having a tough time figuring out how to make it use gnu diff. This gave me the tip I needed.

So, here we go!

0. If you don’t have gnu diff on your machine, install it. (I got mine from sunfreeware.com.) You can just run diff without any args to see the options – if you’re missing “I”, you don’t have the right diff.

1. Set up a wrapper script that uses gnu diff:
:::-->cat /home/gabrielle/bin/ciscodiff.sh
#!/usr/bin/bash
#make git use gnu diff and ignore certain lines
/path/to/gnu/diff
-I 'clock-period'
-I '#time'
-I 'set spantree port.*cost'
$2 $5 | cat

Notes:
– I don’t need the . instead of the space, like I did in the cvs regexp – so this is a more restrictive match. (Which I like.)
– $2 and $5 specify which of the parameters for git diff actually are passed through to this diff. See the “git Diffs” section of the manual.

Make sure to make this executable. :)

2. Then, back in my git repo, I added the following to .git/config:
[diff "ciscoconf"]
command = /home/gabrielle/bin/ciscodiff.sh

3. Then I created .gitattributes, like so:
*-confg diff=ciscoconf

git will now use my special diff wrapper *only* on files with names that match the *-confg glob pattern.

Voila.

Tags:
25 February, 2009

git on Solaris

by gorthx

Boy howdy, was this a trial. Sheesh. (I am in no way pointing fingers at git for this mess…really, it’s this server [that I don’t have admin rights on] that doesn’t behave the way I expect.)

Solaris 10 on x86. (uname -a: SunOS princess 5.10 Generic_125101-10 i86pc i386 i86pc)
git 1.5.6.2

Here’s what I had to do, gathered from various places around the web (the Makefile editing was gleaned mainly from http://discuss.joyent.com/viewtopic.php?pid=175313).

First, I had to install my own gmake, openssl, curl, and a couple of other required libraries.

Then:
./configure --prefix=/home/gabrielle/usr/local
--with-openssl=/home/gabrielle/usr/local/include
--without-tcltk
--without-expat

Edit the makefile:
:::-->diff Makefile Makefile.orig
167,168c167,168
< CFLAGS = -g -O2 -Wall -I/home/gabrielle/usr/local/include
CFLAGS = -g -O2 -Wall
> LDFLAGS =
172d171
< CURLDIR=/home/gabrielle/usr/local
891d889
< NO_ICONV=1

Make sure we’re using gnu make:
:::-->/home/gabrielle/usr/local/bin/make -v
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-pc-solaris2.10

Then install like so:
/home/gabrielle/usr/local/bin/make INSTALL=/usr/ucb/install
/home/gabrielle/usr/local/bin/make INSTALL=/usr/ucb/install install

Voila doesn’t really seem the appropriate thing to say here.

Tags: , ,