有没有一种简单的方法可以更改到以前的活动分支?

发布于 2024-08-08 15:37:05 字数 695 浏览 5 评论 0原文

我在 Windows 上使用 git(实际上是 msysgit)1.6.4。大多数时候我都在一些功能分支上工作。时不时地,我想跳回 master 来挑选我在功能分支中所做的一个特定提交 - 通常是因为它是一个有用的错误修复,即使没有该功能也有意义。我的工作流程是这样的 - 如果这不必要地复杂,请告诉我:-):

git checkout -b mycoolfeaturebranch
// hack away, implementing a feature and one bugfix (while I'm at it)

git add file_with_bugfix.cpp
git commit -m "Fixed bug 12345  // commit the bugfix
git checkout master             // hop over to master
git cherry-pick                 // bring the bugfix into master

此时,我通常想跳回到我的功能分支以继续处理该功能。不幸的是,我的分支名称往往会变得有点长(例如“mycoolfeaturebranch”),而且我在 Windows 上没有 git 分支名称选项卡补全功能。

Unix shell 上是否有类似 cd - 的东西(它会跳转到上一个目录,对于在两个目录之间切换很有用)? git checkout - 会很棒。 :-)

I'm using git (in fact, msysgit) 1.6.4 on Windows. Most of the time I'm doing work in some feature branches. Every now and then, I want to hop back to master to cherry-pick one particular commit I did in my feature branch - usually because it's a useful bugfix which makes sense even without the feature. My workflow is like this - if this is unnecessarily complicated, please tell me :-) :

git checkout -b mycoolfeaturebranch
// hack away, implementing a feature and one bugfix (while I'm at it)

git add file_with_bugfix.cpp
git commit -m "Fixed bug 12345  // commit the bugfix
git checkout master             // hop over to master
git cherry-pick                 // bring the bugfix into master

At this point, I usually want to hop back to my feature branch to continue work on the feature. Unfortunately, my branch names tend to become a little long (like, 'mycoolfeaturebranch') and I don't have git branch name tab completion on Windows.

Is there maybe something like cd - on Unix shells (which hops to the previous directory, useful for toggling between two directories)? A git checkout - would be great. :-)

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

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

发布评论

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

评论(2

弥枳 2024-08-15 15:37:05

来自 $GIT/Documentation/RelNotes-1.6.2.txt:

  • “git checkout -”是“git checkout @{-1}”的简写。

你尝试过吗?

From $GIT/Documentation/RelNotes-1.6.2.txt:

  • "git checkout -" is a shorthand for "git checkout @{-1}".

Did you try it?

安稳善良 2024-08-15 15:37:05

尝试:

 git checkout @{-1}

来自 git rev-parse< /a>:

特殊构造@{-}表示在当前分支之前检出的第一个分支。


正如 Stefan Näwe他的答案

git checkout -”是“git checkout @{-1}”的简写。

尽管语法 @{-1} 已经在 1.6.2 左右出现,但直到 1.6.2 才完全有效,正如 Junio C. Hamano 评论 早在 2009 年 2 月(重点是我的):

早在你开始变得多动之前就添加了 @{-1} 语法
这一轮,但它将出现在 1.6.2 中,并且已被宣传为“可用
在任何可以使用分支名称的地方”,但实际上并非如此

我一直在修复各个地方,以使现实与声明相符。
我现在正在使“git merge @{-1}”工作。


(注意:这与 @{} 不同

后跟后缀 @ 的 ref,以及括在大括号对中的序数规范(例如 {1}{15}),用于指定第 n 个先验该参考值的值。
例如,master@{1} 是 master 的前一个值,而 master@{5} 是 master 的第 5 个先验值。
此后缀只能紧跟在引用名称之后使用,并且引用必须具有现有日志 ($GIT_DIR/logs/)。

您可以使用带有空引用部分的 @ 构造来获取当前分支的引用日志。
例如,如果您位于 blabla 分支,则 @{1}blabla@{1} 含义相同。

Try:

 git checkout @{-1}

From git rev-parse:

The special construct @{-<n>} means the th branch checked out before the current one.


As mentioned by Stefan Näwe in his answer:

"git checkout -" is a shorthand for "git checkout @{-1}".

Even though the syntax @{-1} has been around 1.6.2, it is only since 1.6.2 it is fully effective, as Junio C. Hamano comments back in February 2009 (emphasis mine):

The @{-1} syntax was added long before you started getting hyperactive
this round, but it will be in 1.6.2 and has been advertised as "usable
anywhere you can use a branch name", but in reality it is not
.

I have been fixing up various places to match the reality with the claim.
I am making "git merge @{-1}" work now.


(Note: that differs from @{<n>}

A ref followed by the suffix @ with an ordinal specification enclosed in a brace pair (e.g. {1}, {15}) to specify the n-th prior value of that ref.
For example master@{1} is the immediate prior value of master while master@{5} is the 5th prior value of master.
This suffix may only be used immediately following a ref name and the ref must have an existing log ($GIT_DIR/logs/).

You can use the @ construct with an empty ref part to get at a reflog of the current branch.
For example, if you are on the branch blabla, then @{1} means the same as blabla@{1}.

)

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