Git 推送 &波普德?即,结帐最后状态
我正在编写一个 Bash 脚本,我想签出一个标签,然后签回到我开始的地方。
我尝试了 git co HEAD@{1},但是当从 master 开始时,这让我回到了 master 的提交 SHA,但头分离了。
有没有类似 pushd
& 的东西?用于 Git 的 popd
?
I'm writing a Bash script, and I want to checkout a tag and then checkout back to where I started.
I tried git co HEAD@{1}
, but when starting at master, that takes me back to the commit SHA of master but with a detatched head.
Is there something like pushd
& popd
for Git?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
git checkout @{-1}
可以缩写为git checkout -
。来自联机帮助页:
git checkout @{-1}
which can be abbreviated togit checkout -
.From the manpage:
编辑:如果您不想像 Pushd/popd 那样保留显式历史记录,那么 wnoise 的建议将会起作用。如果您这样做(并且不希望普通的
checkout
影响您的LRU):我不知道有什么可以开箱即用,但它并不难破解沿着这些思路将一些东西结合在一起。如果将名为 git-foo 的文件添加到 PATH,您将获得一个新的 git foo 命令。因此, git-pushd 可能看起来像:
和 git-popd :
EDIT: wnoise's suggestion will work if you don't want to keep an explicit history the way pushd/popd does. If you do (and don't want an ordinary
checkout
to affect your LRU):I don't know of anything that will do what you want out of the box, but it's not to hard to hack together something along those lines. If you add a file named
git-foo
to your PATH, you get a newgit foo
command. So,git-pushd
could look like:And
git-popd
:您还可以使用别名和 /tmp/gitStack 作为临时文件来跟踪堆栈。
查看我创建的主要别名:
You can also do it with aliases and /tmp/gitStack as a temporary file to track your stack.
Checkout the main aliases I've made:
在脚本中,首先保存当前分支(如 这个答案):
然后去签出你想要的标签,
在该分支上做你想做的事情,然后再次签出旧分支:
就是这样。
In your script, first save the current branch (like written in this answer):
then go and checkout the tag you want to
Do what you want to do on that branch, then checkout the old branch again:
That's it.