tags:

views:

298

answers:

1

I'm working on a repository I forked in which the author took the dirty path and stuffed all his dependencies in the lib/ directory in the initial commit. Normally, if it wasn't the initial commit, I would just do an interactive rebase and delete the entire commit (if that's all he did). However, I have no idea how I would edit/delete the initial commit. Is there a way I can edit the initial commit and remove the lib directory without touching the rest of it?

EDIT

I accidentally stumbled upon the answer here: http://stackoverflow.com/questions/575694/can-i-remove-the-initial-commit-from-a-git-repo in the selected answer. That's what I get for not searching more thoroughly.

+2  A: 
$ git filter-branch --parent-filter \
  'test $GIT_COMMIT = SECOND && echo "" || cat' \
  --tag-name-filter cat -- --all

where SECOND is the SHA-1 of the commit you want to be the new root.

The above assumes that all branches use the same first and second commits. If not, you'll need to generalize the test in the parent filter.

Note that this is a drastic measure: it will rewrite your entire history and keep you from following the author's repo. Also if you've pushed your repo to remotes, you'll need to clobber those with git push -f.

Greg Bacon
WARNING: Ref 'refs/heads/master' is unchangedWARNING: Ref 'refs/remotes/origin/master' is unchangedWARNING: Ref 'refs/remotes/origin/master' is unchangedis what it gave me.
Rayne
Ack! You want to rewrite the parents of the *second* commit, not the first. See updated answer, and sorry for the false start.
Greg Bacon
I figured out a different way to do it (shown in my edit) before you edited this post. I'm going to go with the assumption that this actually works (I totally trust you <3) and mark your answer as accepted anyways.
Rayne
Wouldn’t that have been shorter with `echo <SHA of second commit> 0000000000000000000000000000000000000000 > .git/info/grafts; git filter-branch`?
Bombe