5

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: Can I remove the initial commit from a Git repo? in the selected answer. That's what I get for not searching more thoroughly.

Community
  • 1
  • 1
Rayne
  • 31,473
  • 17
  • 86
  • 101

1 Answers1

4
$ 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
  • 134,834
  • 32
  • 188
  • 245
  • WARNING: Ref 'refs/heads/master' is unchanged WARNING: Ref 'refs/remotes/origin/master' is unchanged WARNING: Ref 'refs/remotes/origin/master' is unchanged is what it gave me. – Rayne Jan 14 '10 at 17:21
  • 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 Jan 14 '10 at 18:40
  • 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 Jan 14 '10 at 19:13
  • 1
    Wouldn’t that have been shorter with `echo 0000000000000000000000000000000000000000 > .git/info/grafts; git filter-branch`? – Bombe Jan 15 '10 at 06:01