“git checkout --orphan”有什么用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19980631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is `git checkout --orphan` used for?
提问by jsvisa
I've just discovered git checkout --orphan
, but I don't know how to use it. Its help page says it creates a new unparented branch.
我刚刚发现了git checkout --orphan
,但我不知道如何使用它。它的帮助页面说它创建了一个新的 unparented branch。
In the master
branch, I've tried git checkout --orphan br
, only to see the files in the working directory change to “Changes to be committed”, and the git log
saying fatal: bad default revision 'HEAD'
.
在master
分支,我已经试过git checkout --orphan br
,只看到在工作目录变更的文件“的变化将致力于”,并且git log
说fatal: bad default revision 'HEAD'
。
So what's the advantage of using git checkout --orphan
?
那么使用有什么好处 git checkout --orphan
呢?
采纳答案by JB.
The core use for git checkout --orphan
is to create a branch in a git init
-like state on a non-new repository.
的核心用途git checkout --orphan
是git init
在非新存储库上创建一个类似状态的分支。
Without this ability, allof your git branches would have a common ancestor, your initial commit. This is a common case, but in no way the only one. For example, git allows you to track multiple independent projects as different branches in a single repository.
如果没有这个能力,你所有的 git 分支都会有一个共同的祖先,你的初始提交。这是一种常见的情况,但绝不是唯一的情况。例如,git 允许您将多个独立项目作为单个存储库中的不同分支进行跟踪。
That's why your files are being reported as “changes to be committed”: in a git init
state, the first commit isn't created yet, so all files are new to git.
这就是为什么您的文件被报告为“要提交的更改”的原因:在某个git init
状态下,第一个提交尚未创建,因此所有文件都是 git 的新文件。
回答by Fred Foo
It's used by e.g. GitHub Pages, which stores a repo's website inside the repo but on a separate branch. There's no reason to store anything but the website's history on this branch.
它由例如GitHub Pages 使用,它将存储库的网站存储在存储库内,但位于单独的分支上。除了网站的历史记录之外,没有理由在这个分支上存储任何东西。
回答by user1767754
We were moving to a public repo from a private one and because of sensitive commit information, we wanted to reset a branch as new
and push it as a blank branch. Here is a typical way of a workflow for that:
我们正在从私有仓库转移到公共仓库,由于提交信息敏感,我们想将一个分支重置为new
并将其作为一个空白分支推送。这是一个典型的工作流方式: