在GitHub上创建空分支 [英] Create empty branch on GitHub

查看:184
本文介绍了在GitHub上创建空分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个名为release的新GitHub分支.

I want to create a new GitHub branch, called release.

此分支需要为空!但是,现有分支具有x提交,我不想拥有其提交历史记录.

This branch needs to be empty! However, there is an existing branch with x commits and I don't want to have its commit history.

我发现的唯一方法是创建 local --orphan分支.

The only method I found is to create a local --orphan branch.

推荐答案

--orphan选项出了什么问题?如果您想要的分支是空的并且没有历史记录,这就是要走的路...

What's wrong with the --orphan option? If you want a branch that is empty and have no history, this is the way to go...

git checkout --orphan empty-branch

然后,您可以删除暂存区域中所有的文件(以使它们不会被提交):

Then you can remove all the files you'll have in the staging area (so that they don't get committed):

git rm -rf .

这时,您的计算机上有一个空分支.

At this point you have an empty branch, on your machine.

在您可以推送到GitHub(或其他任何Git存储库)之前,您将至少需要提交一次,即使其中没​​有任何内容(即,空提交),因为您不能推送空分支

Before you can push to GitHub (or any other Git repository), you will need at least one commit, even if it does not have any content on it (i.e. empty commit), as you cannot push an empty branch

git commit --allow-empty -m "root commit"

最后,将其推到遥控器上,然后打开啤酒

Finally, push it to the remote, and crack open a beer

git push origin empty-branch

这篇关于在GitHub上创建空分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆