通过融合查看分支的差异?

发布于 2024-08-16 10:45:07 字数 513 浏览 14 评论 0原文

我知道我可以使用 meld . 查看 HEAD 和当前状态之间的差异。但是我如何查看分支之间的差异,例如使用 meld 的 masterdevel

目前我执行以下步骤:

  1. 重命名工作副本的文件夹
    例如mv /projectA /projectA_master
  2. 再次克隆项目
    git clone url
  3. 切换到devel分支
    cd 项目A && git -b devel origin/devel
  4. 查看与 meld 的差异
    meld /projectA_Master projectA

是否有更简单的方法可以在 meld 中获得相同的结果?我只需要它来查看更改,而不主要用于合并。

I know that I can view the difference between HEAD and current state with meld .. But how can I view the differences between branches, for example master and devel with meld?

At the moment I do the following steps:

  1. Rename folder of working copy
    For example mv /projectA /projectA_master)
  2. Clone the project again
    git clone url
  3. Switch to devel branch
    cd projectA && git -b devel origin/devel
  4. View differences with meld
    meld /projectA_Master projectA

Isn't there an easier way to get the same result in meld? I only need it to review the changes and not primarily for merging.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

忱杏 2024-08-23 10:45:07

短& sweet:

git config --global diff.tool meld

这将 Git 配置为使用 meld 作为 diff 工具。 (您不需要指定命令行参数,Git 内置了对 Meld 的支持。)

然后,如果您想要图形差异而不是文本差异,只需调用 git difftool 而不是 git diff (它们都采用相同的参数)。在您的情况下:

git difftool master..devel

更新:如果您不想要一次一个文件的差异,而是想要使用 meld 的“子目录”视图来显示两个分支之间的所有更改,请注意 -d--dir-diff 选项用于 git difftool。例如,当我在分支 XYZ 上并且我想看看它与分支 ABC 之间有什么不同时,我运行以下命令:

git difftool -d ABC

Short & sweet:

git config --global diff.tool meld

This configures Git to use meld as the diff tool. (You don't need to specify the command line arguments, support for meld is built into Git.)

Then, if you want a graphical diff instead of a textual one, you simply invoke git difftool instead of git diff (they both take the same arguments). In your case:

git difftool master..devel

Update: If you don't want the one-file-at-a-time diff, but instead want to use meld's "subdirectory" view with all the changes between the two branches, note the -d or --dir-diff option for git difftool. For example, when I'm on branch XYZ and I want to see what is different between this and branch ABC, I run this:

git difftool -d ABC
山川志 2024-08-23 10:45:07

从 git v1.7.11 开始,您可以使用 git difftool --dir-diff 来执行目录比较。在没有 https://github.com/wmanley/git-meld 脚本的情况下,它可以很好地与 meld 配合使用。

配置 git

git config --global diff.tool meld

将其用于

git difftool -d topic             // -d is --dir-diff
git difftool -d master..topic

macOS

brew cask install meld
git config --global difftool.meld.cmd 'open -W -a Meld --args \"$LOCAL\" \"$PWD/$REMOTE\"'
git config --global difftool.meld.trustExitCode true

Starting with git v1.7.11, you can use git difftool --dir-diff to perform a directory diff. Which works quite well with meld wihout https://github.com/wmanley/git-meld scripts.

Configure git

git config --global diff.tool meld

Use it

git difftool -d topic             // -d is --dir-diff
git difftool -d master..topic

For macOS

brew cask install meld
git config --global difftool.meld.cmd 'open -W -a Meld --args \"$LOCAL\" \"$PWD/$REMOTE\"'
git config --global difftool.meld.trustExitCode true
蘸点软妹酱 2024-08-23 10:45:07

我还发现这个问题很烦人,所以我制作了 git meld,它允许以更舒适的方式根据工作树或暂存区域区分任意提交。您可以在 https://github.com/wmanley/git-meld 找到它。它有点像 Mark 的脚本,但适用于将任意提交、暂存区域或工作目录与其他任何目录进行比较。如果您要比较的对象之一是工作树,那么它也是读写的,这样您就不会丢失更改。

I also found this issue annoying so I've made git meld which allows a more comfortable way of diffing arbitrary commits against the working tree or the staging area. You can find it at https://github.com/wmanley/git-meld . It's a bit like Mark's script but works for comparing any arbitrary commit or the staging area or the working directory against any of the others. If one of the things you are comparing against is the working tree then that is read-write also so you don't lose your changes.

听不够的曲调 2024-08-23 10:45:07

重要的是,使用 git difftool -d ,您仍然可以在 Meld 中编辑您的工作文件并保存它们。为了实现这一点,您需要将某个分支与当前工作树进行比较,例如:

git difftool -d branchname

Meld 将显示左右目录都位于 /tmp 中。但是,正确目录中的文件实际上是指向当前工作目录中文件的符号链接(不适用于 Windows)。因此,您可以直接在 Meld 中编辑它们,并且当您保存它们时,您的更改将保存在您的工作目录中。

然而更有趣的选择是将当前工作目录与存储目录进行比较。您只需输入以下内容即可做到这一点:

git difftool -d stash

然后您可以将一些更改从 stash(左窗口)传输到当前工作副本(右窗口),而无需使用 git stash pop/apply 并避免麻烦的冲突解决可能是由该命令引起的。

我认为它可以显着提高存储的工作流程。您可以逐渐将更改从存储转移到工作副本,并一一提交它们,如果需要,还可以引入其他一些更改。

It is important to say that using git difftool -d you can still edit your working files in Meld and save them. In order to achieve that you need to compare some branch to your current working tree, for example:

git difftool -d branchname

Meld will be showing that both left and right directories are located in /tmp. However, files in the right directory are actually symbolic links to your files in the current working directory (does not apply to Windows). So you can edit them right in Meld and when you save them your changes will be saved in your working dir.

Yet more interesting option is comparison of current working dir with stash. You can do that by simply typing:

git difftool -d stash

Then you can transfer some changes from stash (left window) to your current working copy (right window), without using git stash pop/apply and avoiding bothersome conflict resolution which may be induced by this commands.

I think that it can significantly boost up workflow with stashes. You can gradually transfer changes from stash to working copy and commit them one by one, introducing some another changes if you want.

↘人皮目录ツ 2024-08-23 10:45:07

尽管从其他答案看来,目前似乎没有办法直接在 git 存储库中执行此操作,但这很容易(感谢 另一个问题 :))编写一个脚本,将两个提交的树提取到临时目录并对它们运行 meld,当 meld 退出时删除两个目录:

http://gist.github.com/498628

当然,您将丢失通过合并所做的任何更改,但我认为这对于快速概述差异非常好。

Although it seems from the other answers as if there's not a way to do this directly in the git repository at the moment, it's easy (thanks to the answer to another question :)) to write a script that will extract the trees of two commits to temporary directories and run meld on them, removing both directories when meld exits:

http://gist.github.com/498628

Of course, you'll lose any changes made via meld, but it's quite nice for a quick overview of the differences, I think.

谎言 2024-08-23 10:45:07

我认为一个简单的方法是使用 git reset --soft :

目标:使用 meld 比较branch_a和branch_b之间的差异

git checkout branch_a
git checkout -b do_diff
git reset --soft branch_b
meld .

I think a easy way for doing this is using git reset --soft:

Goal: compare differences between branch_a and branch_b with meld

git checkout branch_a
git checkout -b do_diff
git reset --soft branch_b
meld .
薄情伤 2024-08-23 10:45:07

对于 macOS 上的 Meld,请按照 维护者的建议将其添加到您的 ~/.gitconfig 中macOS 应用程序的 yousseb

[diff]
  tool = meld
[difftool]
  prompt = false
[difftool "meld"]
  trustExitCode = true
  cmd = open -W -a Meld --args \"$LOCAL\" \"$REMOTE\"
[merge]
  tool = meld
[mergetool]
  prompt = false
[mergetool "meld"]
  trustExitCode = true
  cmd = open -W -a Meld --args --auto-merge \"$LOCAL\" \"$BASE\" \"$REMOTE\" --output=\"$MERGED\"

如果您愿意,可以省略 merge 配置。

由于自动转义和/或 zsh@GutenYe 的答案对我来说不起作用>。

For Meld on macOS, add this to your ~/.gitconfig as recommended by the maintainer of the macOS application, yousseb:

[diff]
  tool = meld
[difftool]
  prompt = false
[difftool "meld"]
  trustExitCode = true
  cmd = open -W -a Meld --args \"$LOCAL\" \"$REMOTE\"
[merge]
  tool = meld
[mergetool]
  prompt = false
[mergetool "meld"]
  trustExitCode = true
  cmd = open -W -a Meld --args --auto-merge \"$LOCAL\" \"$BASE\" \"$REMOTE\" --output=\"$MERGED\"

You can omit the merge configs if you would like.

@GutenYe's answer didn't work out for me due to automatic escaping and/or something with zsh.

落花随流水 2024-08-23 10:45:07

我更喜欢避免 git config 设置并直接获取差异信息。

git difftool --tool=meld -d some_branch_name..other_branch_name

如果您当前签出了 some_branch,则只能指定其他分支名称。

git difftool --tool-help 给出了支持的选项/工具的简洁概述。

I prefer avoiding the git config setup and go right info the diff with

git difftool --tool=meld -d some_branch_name..other_branch_name

You could can only specify the other branch name if you have some_branch checked out currently.

git difftool --tool-help gives a neat overview of the options/tools supported.

活雷疯 2024-08-23 10:45:07

在 git V1.7.9 中,您可以在不使用命令行的情况下比较两个提交:

您必须在“git gui”编辑选项中配置全局:“使用合并工具:meld”。

启动gitk,选择一个提交,右键单击另一个提交> “比较此 --> 选择”。
在“补丁”下右键单击文件> “外部差异”。

meld 将启动并在右侧显示仍然选定的第一个提交。

In git V1.7.9 you can compare two commits without the commandline:

You must configure in 'git gui' edit options, global: "Use merge tool: meld".

Start gitk, select a commit, right click another commit > "diff this --> selected".
Under 'patch' right click a file > "external diff".

meld will start and display the still selected, first commit on the right side.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文