根据您的问题,您的存储库现在如下所示:
o
^
feature
Run Code Online (Sandbox Code Playgroud)
你想让它看起来像这样:
o-------o
^ ^
master feature
Run Code Online (Sandbox Code Playgroud)
同时还在GitHub 上master创建新的默认分支,而不是.feature
一种方法是在分支上创建一个新的“初始”提交feature,将其移动到历史记录的开头并创建一个master指向它的新分支。
步骤如下:
git checkout feature
git commit --allow-empty -m "Initial commit" (you can create the README file here, instead)
git rebase -i --root
# The TODO file will look something like this:
pick 1234abc Adds the feature
pick 5678edg Initial commit
# Move the "Initial commit" line to the top of the file
pick 5678edg Initial commit
pick 1234abc Adds the feature
# Then save and close
Run Code Online (Sandbox Code Playgroud)
此时,您的历史记录将如下所示:
o-------o
^
feature
Run Code Online (Sandbox Code Playgroud)
现在,在 引用的分支之前master创建指向该提交的分支:feature
git checkout -b master feature^
Run Code Online (Sandbox Code Playgroud)
此时,您所要做的就是master使用以下命令推送到 GitHub:
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
最后,您必须转到 GitHub 上的存储库设置才能创建master新的默认分支。请参阅 GitHub 的文档了解如何执行此操作。