Question

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.

Was it helpful?

Solution

$ 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top