有没有办法让git checkout以前的分支? [英] Is there any way to git checkout previous branch?

查看:200
本文介绍了有没有办法让git checkout以前的分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点希望相当于git的 cd - 。如果我在分支 master 和结帐 foo ,我希望能够输入类似于 git checkout - 返回 master ,并且能够再次输入以返回 foo



是否存在这样的事情?难以实现吗?

解决方案

1.6.2发行说明


@ { - 1} 是引用您最后一个分支的一种方式。这是
不仅可以接受对象名称的预期位置,而且可以在任何地方使用
分支名称,并且您可以像输入分支名称一样操作。

E.g. git branch --track mybranch @ { - 1} git merge @ { - 1}

git rev-parse --symbolic-full-name @ { - 1} 可以按预期工作。


git checkout - git checkout @ { - 1} 的缩写。



I sort of want the equivalent of cd - for git. If I am in branch master and I checkout foo, I would love to be able to type something like git checkout - to go back to master, and be able to type it again to return to foo.

Does anything like this exist? Would it be hard to implement?

解决方案

From the release notes for 1.6.2

@{-1} is a way to refer to the last branch you were on. This is
accepted not only where an object name is expected, but anywhere a branch name is expected and acts as if you typed the branch name.
E.g. git branch --track mybranch @{-1}, git merge @{-1}, and
git rev-parse --symbolic-full-name @{-1} would work as expected.

and

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

这篇关于有没有办法让git checkout以前的分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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