破折号在“ git开关”中是什么意思 - ?

发布于 2025-01-23 18:13:00 字数 606 浏览 1 评论 0原文

进行结帐时,我收到了此消息:

$ git checkout HEAD~2
Note: switching to 'HEAD~2'.

You are in a 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits that you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

git Switch中的破折号是什么意思 -?它总是以前的分支吗?

When doing checkout, I got this message:

$ git checkout HEAD~2
Note: switching to 'HEAD~2'.

You are in a 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits that you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

What does the dash mean in git switch -? Is it always the previous branch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷…雨湿花 2025-01-30 18:13:00

git switch 表示以下内容:

您可以使用@{ - n}语法来参考n-th-th-then branch/commits切换到使用“ git switch”或“ > git Checkout“操作。您也可以指定-,它代表@{ - 1}。这通常用于在两个分支之间快速切换,或者错误地撤消分支开关。

因此,-等效于@{ - 1},它代表使用git Switch选择的最后一个提交git Checkout >。

The documentation of git switch states the following:

You can use the @{-N} syntax to refer to the N-th last branch/commit switched to using "git switch" or "git checkout" operation. You may also specify - which is synonymous to @{-1}. This is often used to switch quickly between two branches, or to undo a branch switch by mistake.

Thus, - is equivalent to @{-1} which represents the last commit selected with git switch or git checkout.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文