复制没有历史的git仓库

我目前有一个github上的私人存储库,我想公开。 但是,一些初始提交包含我不想公开的信息(硬编码的创build等)。

公开发布最新的提交的最简单的途径是什么(我真的不需要或不需要在公共存储库中提交以前的提交),而不包括部分或全部提交历史logging?

克隆时可以限制历史的深度:

--depth <depth> Create a shallow clone with a history truncated to the specified number of revisions. 

如果你想有限的历史,但仍然有一些使用这个。

使用以下命令:

 git clone --depth <depth> -b <branch> <repo_url> 

哪里:

  • depth是要包含的提交量。 即如果你只是想要最新的提交使用git clone --depth 1
  • branch是您要从中克隆的远程分支的名称。 即如果你想从master分支的最后3个提交使用git clone --depth 3 -b master
  • repo_url是你的仓库的URL
 #!/bin/bash set -e # Settings user=xxx pass=xxx dir=xxx repo_src=xxx repo_trg=xxx src_branch=xxx repo_base_url=https://$user:$pass@bitbucket.org/$user repo_src_url=$repo_base_url/$repo_src.git repo_trg_url=$repo_base_url/$repo_trg.git echo "Clone Source..." git clone --depth 1 -b $src_branch $repo_src_url $dir echo "CD" cd ./$dir echo "Remove GIT" rm -rf .git echo "Init GIT" git init git add . git commit -m "Initial Commit" git remote add origin $repo_trg_url echo "Push..." git push -u origin master