git:从分离状态重置分支

时间:2012-02-05 07:15:05

标签: git

我做了这个(在我的生产服务器上):

$ git branch
* master
$ git fetch staging
$ git checkout staging/stage1

现在我希望master分支指向HEAD,这是一个SHA-1哈希。我还想更新master reflog。

我该怎么做?

编辑:

澄清“reflog”的含义:我希望{I} $GIT_DIR/logs/refs/heads/master在我完成时再添加一行。也就是说,我想更改master分支,然后让master@{1}指向master分支的确切位置。所以,是的,我指的是回购特定的东西。如果需要的话,我希望能够以某种方式撤消此更改。

我只会做echo .git/refs/remotes/staging/stage1 > .git/refs/heads/master,这会将主分支更改为我想要的位置,但.git/logs文件夹不会更新。

3 个答案:

答案 0 :(得分:1)

git update-ref HEAD master

这将使您当前HEAD所在的“主”点。我不知道你的意思是“希望更新master reflog” - 如果你想更新master日志,那将是因为ref更改而发生的。 reflog 是一个每个存储库的东西,不依赖于特定的分支。

git update-ref

的联系人页面引用
   In general, using
       git update-ref HEAD "$head"
   should be a lot safer than doing
       echo "$head" > "$GIT_DIR/HEAD"

关于更新reflog:

  

如果config参数“core.logAllRefUpdates”为true或文件   “$ GIT_DIR / logs /”存在,然后git update-ref将附加一行   日志文件“$ GIT_DIR / logs /”(解除引用所有符号引用   在创建日志名称之前描述ref值的变化。

答案 1 :(得分:1)

git update-ref refs/heads/master HEAD是我需要的命令。

我显然还需要完全输入分支名称,因为看起来update-ref不够智能,无法“解析”它的参数。意思是,输入“master”作为参数将让git在.git / master创建一个分支,而不是知道我的意思是“refs / heads / master”。

这将更新日志......

If config parameter "core.logAllRefUpdates" is true or the file "$GIT_DIR/logs/<ref>" exists then git update-ref will append a line to the log file "$GIT_DIR/logs/<ref>"

(摘自http://csurs.csr.uky.edu/cgi-bin/man/man2html?1+git-update-ref

答案 2 :(得分:0)

从您当前的状态开始:

git checkout master
git reset -hard HEAD@{1}

但目前尚不清楚你在尝试什么,也不明白你在谈论什么是reflog

相关问题