difftool 如何显示分支更改但避免合并? [英] How difftool can show branch changes but avoiding merges?

查看:25
本文介绍了difftool 如何显示分支更改但避免合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Difftool 显示两个修订版之间的所有更改,避免在合并中进行更改?

How to use Difftool to show all changes between two revisions avoiding changes made in merges?

我可以使用 git log 来显示此命令的更改:

I can use git log to show that changes with this command:

 git log --no-merges -p firstrevinbranch..lastrevinbranch

但是 git log 只显示变更集,而不显示文件,所以我可以正确读取上下文.

But git log only shows changesets, not the file, so I can read the context properly.

有什么方法可以使用 difftool 来执行此操作并显示修订之间的更改以避免合并?我的意思是,在这样的场景中:

Is there any way to use difftool to do this and show changes between revisions buy avoiding merges? I mean, in a scneario like that:

  A---B---C---D topic
 /       /      \
E---F---G---H---I master

我想用 kdiff 仅显示在提交 A、B 和 D 中所做的更改,避免使用 C,因此它是合并提交.

I want to show with kdiff only changes made in commits A,B and D, avoiding C so it's a merge commit.

非常感谢.

推荐答案

简短的回答是你不能".

The short answer is "you can't".

长的答案是你可以,但只有首先创建新的提交,其中有不同的变化.换句话说,与其看你现在有什么,你可以做点别的,然后再看.您通过这样做获得的价值量将部分取决于您制作其他东西时的表现.

The long answer is that you can, but only by first creating new commits that have different changes in them. In other words, rather than looking at what you do have now, you can make something else, and then look at that. The amount of value you get by doing this will depend in part on how well you do when you make the something-else.

这是事实.(这些是快乐的事实还是悲伤的事实取决于您的观点.)提交,在 Git 中,存储一个快照.它不存储更改.快照本身实际上是一个存档.任何现有快照都无法更改,因此它是一个只读存档.

Here are the facts. (Whether these are happy facts or sad facts depends on your point of view.) A commit, in Git, stores a snapshot. It does not store changes. The snapshot itself is literally an archive. No existing snapshot can ever be changed, so it's a read-only archive.

当您将 git difftoolkdiff3 一起使用时,您:

When you use git difftool with kdiff3, you:

  • 让 Git 提取一个或多个提交,以便存档文件可以作为文件访问,而不是打包成仅限 Git 的格式;然后
  • 对这些文件运行 kdiff3,也许让它与您当前的工作树(一个选项)或另一个提取的存档(另一个选项)进行比较.
  • have Git extract one or more commits, so that the archived files are accessible as files instead of being packed up into a Git-only format; then
  • run kdiff3 on these files, perhaps having it compare them to your current working tree (one option) or to another extracted archive (the other option).

因此,以您的示例为例:

So, given your example:

  A---B---C---D topic
 /       /     \
E---F---G---H---I master

您可以使用 git difftool 从提交 A 或提交 BC 中提取快照> 或 D 或 ... 一直到 I.您也可以让它提取任何其他提交,然后在两次提取上运行 kdiff3 ,或者您可以使用第一次提取在其上运行 kdiff3 以及当前的任何内容在您的工作树中.

you can get git difftool to extract the snapshot from commit A, or from commit B, or C or D or ... up through I. You can have it extract any other commit as well, and then run kdiff3 on the two extractions, or you can use the first extraction to run kdiff3 on that and whatever is currently in your working tree.

查看通过在 B 中获取快照,然后对该快照进行更改而形成的假设快照中的内容:

To see what might be in a hypothetical snapshot formed by taking the snapshot in B, then making the changes to that snapshot achieved by:

  1. 找出从CD的变化;然后
  2. 将这些更改添加到 B
  3. 中的快照
  1. finding the changes from C to D; then
  2. adding those changes to the snapshot in B

您实际上必须首先执行步骤 1 和 2.结果可以存储在您喜欢的任何位置:临时目录、全新的存储库或您在这个存储库中所做的提交(临时或永久).Git 可以帮助您进行新的提交.您从实际进行此类提交中获得的价值取决于您,但最简单的方法是:

you will literally have to execute steps 1 and 2 first. The result can be stored anywhere you like: a temporary directory, a whole new repository, or a commit (temporary or permanent) that you make in this repository. Git can assist you with the making a new commit. The value you get from actually making such a commit is, well, up to you, but the easy way to do that is:

  • 检查提交 B,创建一个新分支(临时或永久,随你喜欢):

  • check out commit B, creating a new branch (as temporary or permanent as you like):

git checkout -b temp-branch <hash-of-B>

  • cherry-pick commit D:

    git cherry-pick <hash-of-D>
    

  • 这一切的结果是一个新的提交 J:

    The result of all this is a new commit J:

            J   <-- temp-branch
           /
      A---B---C---D   <-- topic
     /       /     \
    E---F---G---H---I   <-- master
    

    J 中的快照与 B 中的快照之间的差异之间的差异相同或相似 DC 中的快照.出于这个原因,您可能希望通过其他名称来调用 commit J,例如 D',但是您调用什么并不重要> 它;这是一个新的提交,包含一个挑选结果的存档.

    The difference between the snapshot in J and that in B is the same as, or similar to, the difference between the snapshot in D and that in C. For this reason you might want to call commit J by some other name, such as D', but it doesn't really matter what you call it; it's a new commit, containing an archive of the result of the cherry-pick.

    这篇关于difftool 如何显示分支更改但避免合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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