你需要创建一个分支来检出特定的git修订版吗? [英] Do you need to create a branch to check out a specific git revision?

查看:121
本文介绍了你需要创建一个分支来检出特定的git修订版吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的一件事是将我的工作副本恢复到特定版本,进行一些测试,然后将其恢复到我当前主人的头上。在过去,我天真地做了一个混帐检查哈希只是为了失去我的头。自从我学会了我可以创建一个分支并检查出来,然后切换回来并删除分支,但感觉像是进行简单检查的步骤太多了。在SVN的说法中,有没有办法快速恢复,然后迅速回到git的trunk端?



编辑:我想我的困惑源于这样一个事实:当我签出一个散列并且然后签入git日志时,我看不到在签出散列之后发生的变化(当你想到它时这是合理的)。但接受的答案是正确的; git checkout branch会将头部恢复到前一分支。

解决方案

假设你已经在一个分支上(你总是应该为你想要保留的变更),你可以做

  git checkout<修改以检出>> 

这将带您离开您正在研究的主题分支(无分支),其中工作副本直接指向提交ID而不是正常的分支名称。



然后返回,简单地说:

  git checkout<旧分行名称> 

一个有用的方法是:git checkout永远不会改变分支;它只是改变你的工作副本当前正在查看的东西(即HEAD),它可能是一个分支(在这种情况下,提交会更新分支)或随机提交哈希。

因此,只要您想保留的更改位于分支上,您就不必担心git checkout会丢失它们。


A common thing I'd like to do is revert my working copy to a particular revision, do some testing, and then bring it back to the head of my current master. In the past I have naively done a "git checkout hash" only to lose my head. I've since learned I can create a branch and check that out, switch back and delete the branch, but it feels like too many steps for a simple check. In SVN parlance, is there a way to quickly revert and then quickly go back to the tip of trunk in git?

Edit: I think my confusion stems from the fact that when I checkout a hash and then git log, I don't see the changes that happened after the checked out hash (which is reasonable, when you think of it). But the accepted answer is correct; "git checkout branch" will restore the head to the previous branch.

解决方案

Assuming you're already on a branch (which you always should be for changes you want to keep), you can just do

git checkout <revision to check out>

This will take you off the topic branch you were working on into (no branch), in which the working copy refers directly to a commit ID rather than a branch name as normal.

Then to move back, simply:

git checkout <old branch name>

A helpful way to think of it is this: git checkout never alters branches; it merely changes what your working copy is currently looking at (ie, HEAD), which might either be a branch (in which case commits will update the branch) or a random commit hash.

As such, as long as the changes you want to keep are on a branch, you don't have to worry about git checkout losing them.

这篇关于你需要创建一个分支来检出特定的git修订版吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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