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.

4

1 回答 1

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

其中SECOND是您希望成为新根的提交的 SHA-1。

以上假设所有分支都使用相同的第一次和第二次提交。如果没有,您需要在父过滤器中概括测试。

请注意,这是一项严厉的措施:它将重写您的整个历史记录,并阻止您关注作者的回购。此外,如果您已将 repo 推送到遥控器,则需要使用git push -f.

于 2010-01-14T17:15:40.803 回答