是否有更好的方法来实现这个目标,而不是创建一个新的代码库?
$ git checkout --orphan new-master master
$ git commit -m "Initial commit for new root"
# Compare new-master with master to double-check that
# their final commit states are identical:
$ git diff new-master master
# If there is no diff/patch output, then they're identical,
# so it's safe to delete master:
$ git branch -D master
$ git branch --move new-master master
--orphan
标志创建了一个完全独立的提交树,具有不同的根提交。它遵循基本的分支语法,所以后面跟着的参数是新分支的名称,然后是起点,可以是任何Git修订规范,包括提交sha或分支名称。master
分支当前状态相同的状态创建一个新的孤立分支。然后,您需要像第一次使用原始根一样提交新根。new-master
的最终状态确实与master
的最终提交状态相同,因此请对它们进行差异比较以确保(没有差异输出意味着它们相同)。然后进行清理,删除旧的master
分支并将新分支重命名为它。--orphan
标志的解释(第一行由我进行了语法修正):
--orphan <new_branch> [<start_point>]
Create a new orphan branch, named
<new_branch>
, started from<start_point>
and switch to it. The first commit made on this new branch will have no parents and it will be the root of a new history totally disconnected from all the other branches and commits.The index and the working tree are adjusted as if you had previously run
git checkout <start_point>
. This allows you to start a new history that records a set of paths similar to<start_point>
by easily runninggit commit -a
to make the root commit.This can be useful when you want to publish the tree from a commit without exposing its full history. You might want to do this to publish an open source branch of a project whose current tree is "clean", but whose full history contains proprietary or otherwise encumbered bits of code.
If you want to start a disconnected history that records a set of paths that is totally different from the one of
<start_point>
, then you should clear the index and the working tree right after creating the orphan branch by running "git rm -rf .
" from the top level of the working tree. Afterwards you will be ready to prepare your new files, repopulating the working tree, by copying them from elsewhere, extracting a tarball, etc.
git push origin master -f
来强制推送。此外,在 GitHub 上删除分支默认情况下是不被禁止的,除非你没有远程仓库的写入权限,或者你要求 GitHub 支持禁用删除...你为什么在删除方面遇到麻烦? - user456814rm -rf .git/
git init .
~/.git/config
和~/.git/info/exclude
即可。
rm -rf .git; git init .
看起来更简单,尽管你会丢失配置。 - millimoose