Removing '.git' directory from git repo?

ε祈祈猫儿з 提交于 2019-11-28 10:46:15

Use the BFG Repo-Cleaner, a simpler, faster alternative to git-filter-branch specifically designed for removing files from Git history.

Carefully follow the steps here: https://rtyley.github.io/bfg-repo-cleaner/#usage - but the core bit is just this: download the BFG jar (requires Java 6 or above) and run this command:

$ java -jar bfg.jar --delete-folders .git --delete-files .git --no-blob-protection my-repo.git

Your entire repository history will be scanned, and any file or folder named .git will be removed. I've tested this against a specially-constructed test repo containing a .git folder, and it worked just fine.

Thanks to Michel Jouvin for reminding me that files named '.git' are also illegal in Git (and the error message reported by Git doesn't make it immediately obvious that they are files, rather than folders), I've updated this answer to reflect that.

Full disclosure: I'm the author of the BFG Repo-Cleaner.

Have you tried with the following command ?

git filter-branch --tree-filter 'rm -Rf .git' HEAD

git filter-branch documentation indicates that this would be slower than --index-filter, but it could do the job.

Ry4an Brase

As I understand it kiln will let you clone a repository as either git or Mercurial these days, so clone it as mercurial, use the mercurial filemap solution you already found push that Mercurial repo as a new repo to Kiln and then clone it down as git. Then you'll have a git repo you can push to github.

Another way to handle the case where a Mercurial (Hg) repo has a .git folder embedded in it is to first "fix" the Hg repo before exporting to Git. @laurens-holst has a great way of doing this.

If the .git folder was in the root of your project, then your create a text file, my-filemap that looks like:

exclude ".git"

Enable the Convert extension in your .hgrc file:

[extensions]
convert =

Then filter out the .git folder using the Hg convert extension:

hg convert --filemap my-filemap originalrepo newrepo

Now you can export from newrepo and won't have the issue of the embedded .git folder.

You can also use git fsck to make sure the new Git repo is ok before pushing it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!