本文介绍了什么是git-reset的--merge和--keep标志的典型用例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在中,他详细介绍了 git-reset 的三个最常用的选项( - hard , - mixed 和 - soft ),提及 git-reset 还提供了两个相对深奥的标志,称为 - merge 和 - keep 。 的文章,作为一个模型: $ b

然而,我并没有回避对这些标志进行一些小实验,类似于我在中发布的愚蠢的购物清单示例。

解决方案

坦率地说,我对此并不确定;我从来没有使用 - merge 和 - 保持模式。但是,发行说明指出,在git版本1.6.2中添加了 git reset --merge ,注意事项如下:




  • git reset --merge 是一种类似于
    git checkout 开关分支,取得本地更改,而
    切换到另一个提交。



和 - keep 已添加到1.7.1中:




  • git reset learn - 保留选项,可让您放弃在提示附近提交
    ,同时以类似$ b的方式保留本地更改$ b转换为 git checkout分支。



然后在1.7。 9:


  • git checkout -B<当前分支> <其他> 是一种更直观的
    拼写方式 git reset --keep<其他> 。



  • 它告诉我们 - keep 后面的想法是,你已经开始在某个分支上工作,然后你意识到:哦,这个分支应该从其他点(也许是其他分支的尖端)分离出来。举例来说,你可能会:

    $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b

    然后做一些工作来修复下一个版本的bug 1234;但后来有人说:嘿,我们需要修复旧版本的bug 1234!所以,现在你想要 fix-bug-1234 从 release 而不是 devel 。同时你还没有做任何事情。所以你:

      $ git checkout -B fix-bug-1234 release 

    将其移至即将发布而非即将发布。它适用于1.7.9或更高版本,但在1.7.1到1.7.8中,您必须拼写 git reset --keep 。



    这可能解释 - 保留但 - merge 仍然有点神秘。


    In a recent answer in which he details the typical use cases of git-reset's three most commonly used options (--hard, --mixed, and --soft), torek mentions in passing that git-reset also offers two relatively esoteric flags, called --merge and --keep. The git-reset man page describes those two flags as follows:

    I perfectly understand when to use --hard, --mixed, or --soft, but I only learned that --merge and --keep existed while reading torek's answer, and I can't think of practical use cases of those two flags... In what situations do you typically use those two flags?

    I'm mainly looking for a plain-English explanation. Take the following passage of this answer by VonC, which spells out a typical use case for git reset --soft, as a model:

    However, I'm not avert to a little experiment with those flags, similar in spirit to the silly shopping-list example I posted in this answer of mine.

    解决方案

    Frankly I'm not really sure about this; I've never even used the --merge and --keep modes myself. However, the release notes indicate that git reset --merge was added in git version 1.6.2, with the following note:

    • git reset --merge is a new mode that works similar to the waygit checkout switches branches, taking the local changes whileswitching to another commit.

    and --keep was added in 1.7.1:

    • git reset learned --keep option that lets you discard commitsnear the tip while preserving your local changes in a way similarto how git checkout branch does.

    Then, in 1.7.9:

    • git checkout -B <current branch> <elsewhere> is a more intuitiveway to spell git reset --keep <elsewhere>.

    which tells us that the idea behind --keep is, you have started work on some branch, and then you realize: oh, this branch should fork off from some other point (probably the tip of some other branch). For instance you might:

    $ git checkout devel
    $ git checkout -b fix-bug-1234
    

    and then do some work to fix bug 1234 for the next release; but then someone says: "hey, we need bug 1234 fixed for the old release version!" So now you want fix-bug-1234 to branch off from release instead of devel. Meanwhile you haven't committed anything yet. So you:

    $ git checkout -B fix-bug-1234 release
    

    to move it to "coming off release" instead of "coming off devel". Which works in 1.7.9 or later, but in 1.7.1 through 1.7.8 you have to spell it git reset --keep.

    That might explain --keep but --merge is still a bit of a mystery.

    这篇关于什么是git-reset的--merge和--keep标志的典型用例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:17