Sat, 17 Nov 2012

Git cheatsheet

Keywords: git

Merge newer changes on the branch you came from (eg master):

$ git rebase master

Merge your branch:

$ git merge [--no-ff] newbranch

Push a newly created branch upstream:

$ git push -u origin newbranch

-u makes your branch a tracking branch of upstream


Create a new tracking branch:

$ git branch -t newbranch origin/newbranch

Delete remote-tracking branch:

$ git branch -r -d origin/oldbranch

Delete remote branch: (see also

$ git push origin --delete oldbranch

Rewrite history:

$ git rebase -i HEAD~5

Make a branch retroactively (see

$ git checkout -b newbranch
$ git update-ref refs/heads/master origin/master

Merge a branch that should have been rebased:

$ git fetch upstream_branch:local_newbranch
$ git checkout local_newbranch
$ git rebase master
$ git checkout master
$ git merge -ff-only local_newbranch
$ git branch -d local_newbranch

Create a branch for a pull request:

$ git pull upstream_branch:local_newbranch

Move a branch to a new commit:

$ git branch -f branch_name new_tip_commit

Look at a file from an previous revision:

$ git cat-file -p <sha1>:filename

[/revision_control] permanent link

Sat, 25 Sep 2010

Splitting a git repository

Keywords: git directory subdirectory separate detach filter-branch

I had a bunch of directories in a single git repository and I wanted to make each one into its own repository. It turns out to be fairly simple. Suppose that the original repository is called orig and the directories in it are called dir1, dir2 etc. For each directory:

$ git clone --no-hardlinks orig dir1
$ cd dir1
$ git filter-branch --subdirectory-filter dir1 HEAD -- --all
$ git remote rm origin
$ rm -r .git/refs/original/
$ git reflog expire --expire=now --all
$ git gc --aggressive
$ git prune
$ du -sh *
$ git log

[/revision_control] permanent link

Sat, 27 May 2006

Updating SVN::Web

I noticed recently that my SVN::Web pages had stopped working. Today I found a little time to investigate. My apache error log said:

Can't locate object method "caught" via package "SVN::Web::X"
at /usr/local/share/perl/5.8.7/SVN/


I remembered having a bit of hassle installing it first time around primarily because it wasn't ready for Apache2, so I punched "SVN::Web Apache2" into Google, and surprised myself when I noticed that my notes page was the second hit. It was top on MSN.

Aha! So that's the reason I write these notes!

My notes told me which modules I could let debian install and which I had to manage myself. They also told me the hacks I had made to make things work with Apache2.

So in these situations I normally make sure I'm running the latest versions of everything. The bug I'm chasing might already be fixed. The first thing I noticed was that there was a new version of SVN::Web iteslf. So I installed it.

Since I had first installed SVN::Web debian had upgraded from Perl 5.8.7 to 5.8.8, so the latest SVN::Web installed into a slightly different directory. During the installation it told me that Exception::Class was out of date and asked if it should be updated. I declined since currently Exception::Class was installed as a debian package and I was hoping it could stay that way. (In fact, I had also installed it from CPAN, but didn't read enough of my notes to notice that.)

After installing the latest SVN::Web, I tried running it, just to see what happened. I was expecting loads of errors since my hacky patches were now lost. In fact, I got exactly the same error as before. Good News! That seemed to show that SVN::Web now works with Apache2, and my hacks were no longer required.

But the original problem remained. So I installed the latest Exception::Class, which hadn't yet made it into debian, tried again and everything just worked.


Now, if only there was a debian package of SVN::Web so that someone else could worry about all this.

So once again I battled SVN::Web and debian and I prevailed! And once again you can see the results at svnweb.

[/revision_control] permanent link

Wed, 01 Feb 2006

Recovering SVN bdb Repositories

I looked at a few of my older SVK repositories and found that debian had upgraded bdb under me and so the repositories couldn't be read. The error message was something like:

Berkeley DB error: Berkeley DB error for filesystem /home/pjcj/g/svk/testr/db while opening environment:
DB_VERSION_MISMATCH: Database environment version mismatch: bdb: Program version 4.3 doesn't match environment version

The solution was to find a copy of svnadmin which was statically linked to the older library and use that to help upgrade the repository. While I was there, I moved the remainder of my repositories to fsfs.

I found such an svnadmin binary at after which the sequence of commands is:

$ /path/to/static/svnadmin recover repository
$ /path/to/static/svnadmin dump repository > repository.dmp

At this point you could upgrade your bdb repository if you wanted to. I just blew it away and created a new fsfs repository. (Well, I was a little more careful.)

$ mv repository repository.bdb
$ svnadmin create repository
$ svnadmin load repository < repository.dmp

And then everything worked again.

[/revision_control] permanent link

Mirroring base

Here's how I set up my base utilities on a new machine. It's not optimal by a long shot, but it's pretty easy.

% aptitude install svk
$ cd ~
$ svk depot --init
$ svk cp http://svk.server/svn/base
$ rm -r base
$ cd g
$ svk co //base/trunk base
$ cd ..
$ ln -s g/base/* g/base/.* .

[/revision_control] permanent link

Installing SVN::Web

It's really about time I made my SVK repositories public, and as a first step towards that I decided to install SVN::Web. I'm running debian, and since the Perl SVN bindings are such a pain to install I am using the system perl to run SVK. This means that I also need to use the system perl to run SVN::Web.

The first thing I did was to install debian's mod_perl. That wasn't too hard:

# aptitude install libapache2-mod-perl2

and everything still seemed to work. Now the problem is that SVN::Web isn't packaged for debian, so the installation is going to need to be an unholy mix of debian packages and CPAN modules. I decided to try to install as many of the debian packages as I could and install the remainder from CPAN. So, the debian packages I installed were:

# aptitude install libtemplate-perl libpod-coverage-perl \
      libtest-differences-perl libmodule-build-perl libtext-diff-perl \
      libxml-rss-perl libexception-class-perl libtemplate-perl-doc \
      libapache2-request-perl libnumber-format-perl \
      libtemplate-plugin-clickable-perl libemail-find-perl

They might not all be strictly necessary.

Then I needed to install some modules from CPAN:

# perl -MCPAN -e shell
cpan> install SVN::Web
cpan> install Exception::Class
cpan> install Devel::StackTrace
cpan> install Template::Plugin::Number::Format
cpan> install Text::Diff::HTML
cpan> install Template::Plugin::Clickable::Email

I had to install Exception::Class from CPAN since the debian version was too old. Without Text::Diff::HTML the process would just sit there eating all the CPU when you asked for HTML diffs. Without Template::Plugin::Clickable::Email the error log filled up saying it wasn't there.

Then I added to /etc/apache2/sites-available/default :

<Directory /var/www/svnweb>
    AllowOverride None
    Options None
    SetHandler perl-script
    PerlHandler SVN::Web

<Directory /var/www/svnweb/css>
    SetHandler default-handler

Then I had to hack on itself to make it work with Apache2. The diff below seems to work for me, though it might well be either overkill or underkill.

--- /usr/local/share/perl/5.8.7/SVN/	2006-01-30 20:37:46.000000000 +0100
+++ /usr/local/share/perl/5.8.7/SVN/	2006-01-30 22:50:42.000000000 +0100
@@ -861,15 +861,17 @@
 sub handler {
     eval "
-	use Apache::RequestRec ();
-	use Apache::RequestUtil ();
-	use Apache::RequestIO ();
-	use Apache::Response ();
-	use Apache::Const;
-	use Apache::Constants;
-        use Apache::Request;
+	use Apache2::RequestRec ();
+	use Apache2::RequestUtil ();
+	use Apache2::RequestIO ();
+	use Apache2::Response ();
+	use Apache2::Const;
+	use Apache2::Const;
+        use Apache2::Request;
+    die $@ if $@;
     my $r = shift;
     eval "$r = Apache::Request->new($r)";
     my $base = $r->location;
@@ -921,7 +923,7 @@
     mod_perl_output($cfg, $html);
-    return &Apache::OK;
+    return &Apache2::Const::OK;
 =head1 SEE ALSO

So I battled SVN::Web and debian and I prevailed! You can see the results at svnweb.

[/revision_control] permanent link

September 2017
Sun Mon Tue Wed Thu Fri Sat