Git分支目录比较

发布于 2024-10-04 12:45:58 字数 317 浏览 6 评论 0原文

我最喜欢的 svn 工作流程之一是使用 Beyond Compare 的文件夹比较功能来查看两个分支或分支与主干之间的净差异。有没有办法在 git 中执行此操作,而无需手动创建同一存储库的多个克隆?

当我问这个问题时,我突然想到我可以编写一个脚本,将当前存储库克隆到临时目录,签出所需的分支,然后使用两个目录作为参数调用 BCompare.exe。文件夹比较视图通过

BCompare.exe path/to/folder1 path/to/folder2

这听起来合理吗?使用 Beyond Compare 后我可以删除多余的克隆吗?

One of my favorite workflows with svn is to use Beyond Compare's folder comparison feature to see the net differences between two branches, or a branch and the trunk. Is there a way to do this in git without having to manually create multiple clones of the same repository?

As I ask this question, it occurs to me that I could write a script that would clone the current repo to a temporary directory, checkout the desired branch, and then call BCompare.exe with the two directories as arguments. The folder comparison view is invoked with

BCompare.exe path/to/folder1 path/to/folder2

Does this sound reasonable? Would I be able to delete the extra clone after I'm done with Beyond Compare?

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

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

发布评论

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

评论(4

心如狂蝶 2024-10-11 12:45:58

这个(比较目录而不是逐个文件)应该很快就会可用:
请参阅[公告] Git 1.7.11.rc1

git difftool”学习了“--dir-diff”选项来生成外部比较工具,该工具可以比较两个目录层次结构填充两个临时目录后的一段时间,而不是每个文件对运行一次外部工具的实例

请参阅“补丁 difftool:教 difftool 处理目录差异”,来自此 git 分支

当调用“difftool”来比较修改多个文件的一系列提交时,它会为每个更改的文件打开 diff 工具的单独实例。

新的“--dir-diff”选项将所有修改的文件复制到临时位置,并在 diff 工具的单个实例中对它们运行目录 diff。

This (comparing directories instead of file-by-file) should be available soon:
See [ANNOUNCE] Git 1.7.11.rc1:

"git difftool" learned the "--dir-diff" option to spawn external diff tools that can compare two directory hierarchies at a time after populating two temporary directories, instead of running an instance of the external tool once per a file pair.

See "Patch difftool: teach difftool to handle directory diffs", from this fork of git:

When 'difftool' is called to compare a range of commits that modify more than one file, it opens a separate instance of the diff tool for each file that changed.

The new '--dir-diff' option copies all the modified files to a temporary location and runs a directory diff on them in a single instance of the diff tool.

遗弃M 2024-10-11 12:45:58

听起来您已经找到了正确的答案 - 使用 git clone 和 git checkout 设置要比较的目录,然后运行 ​​BCompare。 exe.下面的脚本可能是一个很好的起点。

#!/bin/sh
(                              # execute in a subshell so you can continue
                               #   working in the current shell
    set -o xtrace              # bash setting that echos each command before it's executed
    > /tmp/auto_bcompare_log   # truncate existing log file
    BRANCH="$1"                # get branch argument from command line
    TEMPDIR=`mktemp -d`        # get a temp directory
    CWD=`pwd`                  # remember the current directory
    git clone $CWD $TEMPDIR
    cd $TEMPDIR
    git checkout $BRANCH
    cd $CWD
    BCompare.exe $CWD $TEMPDIR
    rm -rf $TEMPDIR
) >> /tmp/auto_bcompare_log 2>&1 < /dev/null & # background and redirect
                                               # stdout/stderr/stdin

It sounds like you've already figured out the right answer -- use git clone and git checkout to set up a directory to compare to, then run BCompare.exe. The below script might be a good starting point.

#!/bin/sh
(                              # execute in a subshell so you can continue
                               #   working in the current shell
    set -o xtrace              # bash setting that echos each command before it's executed
    > /tmp/auto_bcompare_log   # truncate existing log file
    BRANCH="$1"                # get branch argument from command line
    TEMPDIR=`mktemp -d`        # get a temp directory
    CWD=`pwd`                  # remember the current directory
    git clone $CWD $TEMPDIR
    cd $TEMPDIR
    git checkout $BRANCH
    cd $CWD
    BCompare.exe $CWD $TEMPDIR
    rm -rf $TEMPDIR
) >> /tmp/auto_bcompare_log 2>&1 < /dev/null & # background and redirect
                                               # stdout/stderr/stdin
从此见与不见 2024-10-11 12:45:58

只需使用 git diff 加上要比较的分支的名称或哈希值,就这么简单。实际上,您可以通过哈希值来比较任意两个提交。

Just git diff with the names or hashes of the branches you want to compare, simple as that. Actually, you can compare any two commits by their hashes.

恬淡成诗 2024-10-11 12:45:58

首先验证您是否具有超越比较功能,

您可以使用: git difftool --tool-help 列出可用的比较工具。
(要将其设置为默认值,请参阅 Git Diff 与 Beyond Compare

如果您有 Beyond Compare你可以使用其中之一:

git difftool branch1 branch2 file -t bc   // or -d directory instead of file
git difftool hash1   hash2   file -t bc

编辑:适用于 git 版本 2.25

First verify you have beyond compare accessible,

you can use: git difftool --tool-help to list the available compare tools.
(to set it as default see Git Diff with Beyond Compare)

If you have beyond compare you can use one of those:

git difftool branch1 branch2 file -t bc   // or -d directory instead of file
git difftool hash1   hash2   file -t bc

EDIT: works in git version 2.25

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