如何找出正在进行的合并的父版本? [英] How to find out parent revisions of an in-progress merge?

查看:184
本文介绍了如何找出正在进行的合并的父版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始了合并,但是我已经解决了冲突,现在已经准备好提交了。我只是想仔细检查一下我已经合并了哪些父版本。



到目前为止已经尝试过的东西:


  • git show 与%P格式说明符 - 除了我不知道如何让它告诉我未提交合并的父母

  • git rev-list 与各种选项无关

  • code> hg parents ,其中将我带回 git rev-list 但没有成功:它列出了 5个修订版,并且未能列出实际传递给 git merge< rev>的修订版;

  • git commit 并查看提交消息 ul>

    最后一个是真正有用的唯一选项,除了它只显示我未提交合并的父项之一。



    有一个比 git commit 更好的方法!如何正确执行此操作?

    解决方案

    请注意,因为合并提交尚不存在,所以您不会可以使用 git log git show %P 格式说明符(它对应于父哈希)来访问未来合并提交的父项。

    简单合并



    如果一个分支简单合并到另一个分支中,您可以运行

      git log -n 1 --pretty = format:%H
    git log -n 1 --pretty = format:%HMERGE_HEAD

    ,它将打印当前分支的尖端


    • 的完整SHA, / li>
    • 分支被合并,





    八达通合并



    如果在章鱼合并过程中出现任何冲突,包括合并多个分支到另一个分支,Git会中止我RGE;因此,你的问题通常不适用于这种情况。正如Andrew在中指出的那样他的评论,尽管 --no-commit 标志可用于故意中断合并,即使它没有冲突。但是,在这种情况下,运行

    git log -n 1 --pretty = format: %HMERGE_HEAD

    只会打印分支的一个的SHA被合并;它不会列出这些分支的所有的SHA。



    尽管如此,有一种方法可以打印所有这些文件。事实证明, .git / MERGE_HEAD 文件包含被合并的分支的所有的SHA;因此,更强大的方法是简单地转储该文件的内容:

      cat .git / MERGE_HEAD 

    为了解决这个问题,下面是一个中断章鱼合并的例子: / p>

     #设置事物
    $ mkdir test_octopuss
    $ cd test_octopuss
    $ git init

    #创建一个初始提交
    $ printffoo\\\
    > README.md
    $ git add README.md
    $ git commit -m在自述文件中添加foo'

    #在分支上创建三个不同的提交,作为父母提交
    $ printfbar\\\
    >> README.md
    $ git commit -am在README中添加'bar'
    $ git checkout -b另一个主文件^
    $ printfbar\\\
    >> README.md
    $ git commit -am在'自述文件'中添加'bar'
    $ git checkout -b另一个主人^
    $ printfbar\\\
    >> README.md
    $ git commit -am在README中添加'bar'

    #获取我们的轴承
    $ git log --oneline --graph --all - 装饰
    * 93e4667(HEAD,另一个)在自述文件中添加'bar'
    | * a114920(另一个)在README
    | /
    |中添加'bar' * 7adc927(master)在自述文件中添加'bar'
    | /
    * bc400cd在自述文件中添加'foo'

    #使用--no-commit标志合并(假装合并失败)
    $ git merge --no-commit master另一个
    尝试简单合并主
    尝试简单合并另一个
    自动合并进行得很顺利;在提交之前停止请求

    #以下命令未能列出所有正在合并的元素
    $ git log -n 1 --pretty = format:%HMERGE_HEAD
    7adc927d9f7a0c8864d0ff784c0c53b0ded00616

    #在当前分支中合并的所有头的列表
    $ cat .git / MERGE_HEAD
    7adc927d9f7a0c8864d0ff784c0c53b0ded00616
    a114920072210417a1fa6c9b2b33b5729097ee93


    I've started a merge, but it had conflicts which I've resolved, and now it's all staged ready for commit. I just want to double-check which parent revisions I've merged.

    Things tried so far:

    • git show with the %P format specifier - except I cannot figure out how to get it to tell me the parents of the uncommitted merge
    • git rev-list with various options, to no avail
    • googling for a git equivalent to hg parents, which brings me back to git rev-list but with no success: it lists five revisions, and it fails to list the revision I actually passed to git merge <rev>
    • git commit and look at the commit message

    The last one is the only option that really kind of worked, except it only shows one of the parents of my uncommitted merge.

    There's got to be a better way than git commit! How do I do this properly?

    解决方案

    Note that, because the merge commit doesn't exist yet, you won't be able to use git log or git show with the %P format specifier (which corresponds to parent hashes) to access the parents of that future merge commit.

    Simple merge

    In case of a simple merge of one branch into another, you can run

    git log -n 1 --pretty=format:"%H"
    git log -n 1 --pretty=format:"%H" MERGE_HEAD
    

    which will print the full SHAs of

    • the tip of the current branch, and
    • the branch being merged in,

    respectively.

    Octopus merge

    If any conflict arises during an octopus merge, which involves merging more than one branch into another, Git will abort the merge; therefore, your question wouldn't normally apply to that case. As pointed out by Andrew in his comment, though, the --no-commit flag can be used to intentionally interrupt the merge, even if it's free of conflicts. However, in that case, running

    git log -n 1 --pretty=format:"%H" MERGE_HEAD
    

    will only print the SHA of one of the branches being merged in; it won't list the SHAs of all of those branches.

    Everything's not lost, though; there is a way of printing all of them. It turns out that the .git/MERGE_HEAD file contains the SHAs of all the branches being merged; therefore, a more robust approach consists in simply dumping the contents of that file:

    cat .git/MERGE_HEAD
    

    To fix ideas, here is a (voluntarily contrived) example of an interrupted octopus merge:

    # set things up
    $ mkdir test_octopuss
    $ cd test_octopuss
    $ git init
    
    # create an initial commit
    $ printf "foo\n" > README.md
    $ git add README.md
    $ git commit -m "add 'foo' in README"
    
    # create three different commits on branches whose tips count the root commit as parent
    $ printf "bar\n" >> README.md 
    $ git commit -am "add 'bar' in README"
    $ git checkout -b another master^
    $ printf "bar\n" >> README.md 
    $ git commit -am "add 'bar' in README"
    $ git checkout -b yetanother master^
    $ printf "bar\n" >> README.md 
    $ git commit -am "add 'bar' in README"
    
    # get our bearings
    $ git log --oneline --graph --all --decorate
    * 93e4667 (HEAD, yetanother) add 'bar' in README
    | * a114920 (another) add 'bar' in README
    |/  
    | * 7adc927 (master) add 'bar' in README
    |/  
    * bc400cd add 'foo' in README
    
    # merge using the --no-commit flag (to pretend that the merge failed)
    $ git merge --no-commit master another
    Trying simple merge with master
    Trying simple merge with another
    Automatic merge went well; stopped before committing as requested
    
    # the following command fails to list all the heads being merged in
    $ git log -n 1 --pretty=format:"%H" MERGE_HEAD
    7adc927d9f7a0c8864d0ff784c0c53b0ded00616
    
    # list of all the heads being merged in the current branch
    $ cat .git/MERGE_HEAD
    7adc927d9f7a0c8864d0ff784c0c53b0ded00616
    a114920072210417a1fa6c9b2b33b5729097ee93
    

    这篇关于如何找出正在进行的合并的父版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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