当合并冲突时合并git笔记 [英] Merging git notes when there are merge conflicts in them

查看:98
本文介绍了当合并冲突时合并git笔记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了以下合并Git笔记。

ref: http: //vmiklos.hu/blog/git-notes-merge


我克隆了一个回购,添加了对提交的注释引用(refs / notes / commits)。当我推动它时,中央repo拒绝它,因为它是非快进的 - 因为已经有一个提交对象的refs / notes / commit。因此,为了将远程Notes引用合并到我的本地Notes引用,



  1. git checkout refs / notes / master
  2. git fetch refs / notes / commitits

  3. git merge FETCH_HEAD

    自动合并206155715a78c9d91d42cda1de98449d2e0b1d36 <
    CONFLICT(添加/添加):合并206155715a78c9d91d42cda1de98449d中的冲突........

    自动合并失败;修复冲突,然后提交结果。

  4. vi 206155715a78c9d91d42cda1de98449d ........ [手动修复冲突]

  5. git add 206155715a78c9d91d42cda1de98449d ........


  6. git commit -m更新备注

    [detached HEAD 0afb80f] changed注释

  7. git update-ref refs / notes /提交头文件

  8. git checkout master

    上一页HEAD位置为0afb80f ...更改了注释

    转换为分支'master'

  9. git push原始参考/注释/提交



现在的问题是,这是否是最好的方法?



继git notes man page之后,我尝试了以下方法。
$ b



  1. git fetch refs / notes / commitits

  2. git notes merge -v refs / notes / commitits

    无法更新!


以上步骤显然对我有用。有没有办法使用git notes merge命令并合并Notes,而不是像第一个插图所示的分支方法?对于我的用户来说,这个简单的命令会更有帮助。

解决方案

正如我在评论中已经提到的那样,方法不适用于你是你复制了错误的指令:你的第二步 git fetch refs / notes / commitits 缺少远程名称。



关于使用 git notes merge 的第二种方法,再次犯了同样的错误,即从 git fetch 。但即使有了这个修正,我仍然努力让它发挥作用,直到我最终发现在合并之前必须从远程获取笔记到不同的ref命名空间中,因为如果发生冲突,它不会让你覆盖什么本地 refs / notes / commitits 指向(尽管如果没有冲突它会快乐地将它快进)。



所以这适用于我:

  git fetch origin refs /注释/提交:refs / notes / origin / commitits 
git notes merge -v origin / commitits



<如果存在冲突,它现在会告诉你编辑 .git / NOTES_MERGE_WORKTREE 然后通过提交结果git notes merge --commit ,或者用 git notes merge --abort 中止合并。

一个很大的缺点使用 git notes merge 超过在上面的URL是合并不提供任何索引,所以你不能通过 git mergetool 等来使用正常的合并工作流程。另一个原因是它没有提供任何索引不支持重新分配。所以,如果你期望复杂的冲突或需要rebase,那么我建议使用 git checkout refs / notes / commitits 方法。但在简单情况下, git notes merge 可能更方便,因为您可以在工作树很脏的情况下执行合并,而 git checkout refs /笔记/提交要求它干净。



我很确定 git-notes(1) 手册页可以使这一切变得更加明显。也许我会找点时间为此提交补丁。同时,我写了一个新的包装器,名为 git-rnotes ,这样可以更轻松地与远程存储库共享笔记。


I did the following to merge Git notes.
ref : http://vmiklos.hu/blog/git-notes-merge

I cloned a repo, added notes reference to the commit (refs/notes/commits). When i push it, central repo rejects it as it was non-fast forward - because there was already a refs/notes/commits for that commit object. So inorder to merge that remote Notes reference to my local Notes reference,

  1. git checkout refs/notes/master
  2. git fetch refs/notes/commits
  3. git merge FETCH_HEAD
    Auto-merging 206155715a78c9d91d42cda1de98449d2e0b1d36
    CONFLICT (add/add): Merge conflict in 206155715a78c9d91d42cda1de98449d........
    Automatic merge failed; fix conflicts and then commit the result.
  4. vi 206155715a78c9d91d42cda1de98449d........ [fix the conflict as usual manually]
  5. git add 206155715a78c9d91d42cda1de98449d........
  6. git commit -m "updated Notes"
    [detached HEAD 0afb80f] changed notes
  7. git update-ref refs/notes/commits HEAD
  8. git checkout master
    Previous HEAD position was 0afb80f... changed notes
    Switched to branch 'master'
  9. git push origin refs/notes/commits
    success

The question is, whether is this the best way to do this?

Following git notes man page, i tried the following.

  1. git fetch refs/notes/commits
  2. git notes merge -v refs/notes/commits
    Nothing to Update!

The above steps obviously dint work for me. Is there a way to use the git notes merge command and merge the Notes, rather than the "branch method" as shown in the first illustration? For my users, this straightforward command would be more helpfull.

解决方案

As I already alluded to in a comment, one reason the first approach is not working for you is that you copied the instructions wrong: your second step git fetch refs/notes/commits is missing the name of the remote.

Regarding the second approach with git notes merge, again you have made the same mistake of missing the remote from the git fetch. But even with this fixed I struggled to get it to work until I finally figured out that you have to fetch the notes from the remote into a different ref namespace prior to merging, since if there is a conflict it won't let you overwrite what the local refs/notes/commits points to (although it will happily fast-forward it if there is no conflict).

So this works for me:

git fetch origin refs/notes/commits:refs/notes/origin/commits
git notes merge -v origin/commits

If there are conflicts, it will now tell you to edit .git/NOTES_MERGE_WORKTREE and then commit the result via git notes merge --commit, or abort the merge with git notes merge --abort.

One big disadvantage of using git notes merge over the technique suggested in the URL above is that the merge does not provide any index, so you can't use your normal merging workflow via git mergetool etc. Another is that it doesn't support rebasing. So if you expect complicated conflicts or need to rebase then I'd recommend going with the git checkout refs/notes/commits approach. But in the simple case, git notes merge is probably more convenient because you can perform the merge whilst your working tree is dirty, whereas git checkout refs/notes/commits requires it to be clean.

I'm pretty sure that the git-notes(1) man page could make this all a lot more obvious. Maybe I'll find some time to submit a patch for that. In the mean time however, I've written a new wrapper called git-rnotes which makes it easier to share notes to and from remote repositories.

这篇关于当合并冲突时合并git笔记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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