Git分支的目录比较 [英] Directory comparison of Git branches
问题描述
我最喜欢的svn工作流程之一是使用Beyond Compare的文件夹比较功能来查看两个分支之间或分支和中继线之间的净差异。有没有办法在git中做到这一点,而无需手动创建同一个存储库的多个克隆?
当我问这个问题时,我发现我可以编写一个脚本,将当前的repo克隆到临时目录,检出所需的分支,然后调用BCompare.exe以两个目录作为参数。文件夹比较视图用
BCompare.exe路径/ to / folder1路径/ to / folder2
这听起来合理吗?在完成Beyond Compare之后,我能够删除额外的克隆吗? 解决方案
听起来你已经找出正确的答案 - 使用 git clone
和 git checkout
来设置一个目录来比较,然后运行 BCompare.exe
。下面的脚本可能是一个很好的起点。
#!/ bin / sh
(#在子shell中执行所以你可以继续
#在当前shell中工作
set -o xtrace#bash在执行之前设置每个命令的回显
> / tmp / auto_bcompare_log#截断现有日志文件
BRANCH =$ 1#从命令行获取分支参数
TEMPDIR =`mktemp -d`#获取临时目录
CWD =`pwd`#记住当前目录
git clone $ CWD $ TEMPDIR
cd $ TEMPDIR
git checkout $ BRANCH
cd $ CWD
BCompare.exe $ CWD $ TEMPDIR $ b $ r rm -rf $ TEMPDIR
) >> / tmp / auto_bcompare_log 2>& 1< / dev / null& #background and redirect
#stdout / stderr / stdin
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?
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
这篇关于Git分支的目录比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!