是否可以使用 winmerge 查看 cygwin 的 git diff?

发布于 2024-09-16 21:29:24 字数 167 浏览 10 评论 0原文

我喜欢在 cygwin 上使用 git,但唯一的缺点是当我想要 git difftool 时我无法使用任何有用的东西。 git diff 大多数时候对我来说没问题,但有时我想使用 winmerge 通过 git difftool 查看这些差异,有什么方法可以设置它吗?

I like to use git on cygwin, but the only downside I have is when I want to git difftool I cannot use anything useful. git diff is fine for me most of the time, but sometimes I'd like to use winmerge to view these diffs via git difftool is there some way to set this up?

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

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

发布评论

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

评论(1

戏舞 2024-09-23 21:29:24

对于 cygwin,SO 问题“如何我可以将 Mercurial 配置为在 cygwin 下使用 WinMerge 进行合并吗?”可以应用于 git(将以下 winmerge 脚本与旧问题“使用 Git 内部的 Winmerge 来文件 diff")

#!/bin/sh
"/cygdrive/c/Program Files/WinMerge/WinMergeU.EXE" /e /ub /dl other /dr local `cygpath -aw $1` `cygpath -aw $2` `cygpath -aw $3`

流程

您可以在这篇文章“Git + WinMerge + Cygwin" (来自 Thiru Thirunavukarasu):
(但我仍然推荐上面的 WinMergeU.exe 选项)

将以下行添加到您的 .gitconfig 文件中:

  [diff]
    tool = winmerge
  [difftool "winmerge"]
    cmd = git-difftool-winmerge-wrapper.sh \"$LOCAL\" \"$REMOTE\"
  [difftool]
    prompt = false

最后一个选项(prompt = false)是可选的。如果您确实希望 Git 在打开每个差异之前提示您,您可以省略它。

创建一个名为 git-difftool-winmerge-wrapper.sh 的文件并将其放置在您的路径中。
我只是将它放在我的主目录中。您可以通过修改 .bash_profile 文件(也在您的主目录中)并添加 PATH=${PATH}:${HOME}

来更改默认的 Cygwin 路径以包含您的主目录

将以下内容添加到git-difftool-winmerge-wrapper.sh

  #!/bin/sh
  echo "Launching WinMergeU.exe \"$(cygpath -aw "$1")\" \"$(cygpath -aw "$2")\""
  if [ -f "$1" -a -f "$2" ]
  then
    "C:/Program Files (x86)/WinMerge/WinMergeU.exe" -e -u -wl -dl "Base" -dr "Mine" "$(cygpath -aw "$1")" "$(cygpath -aw "$2")"
  else
    echo "skipping as one file doesn't exist"
  fi

再次,使用这些 WinMerge 选项进行一些测试)


脚本

如果您想使用“所有 WinMerge”,对于 diff 和 merge git 功能,您可以使用以下 < a href="https://gist.github.com/509918" rel="nofollow noreferrer">要关注的要点页面来自 ecerulm (Ruben Laguna):

diffmerge-diff.sh

#!/bin/sh
# Use SourceGear DiffMerge as mergetool for git in cygwin.
#   git config --global mergetool.diffmerge.cmd "diffmergetool.sh \"\$LOCAL\" \"\$REMOTE\" \"\$BASE\" \"\$MERGED\""
#   git config --global mergetool.diffmerge.trustExitCode false
#   git difftool -t diffmerge branch1..branch2

# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf

library=githelperfunctions.sh

#[ -f $library ] && . $library
. $library

echo Launching DiffMerge.exe - diffmerge-diff.sh: 

set_path_vars "$1" "$2" "$3" "$4"

echo "$diffmergewinpath" -t1=FROM_VERSION -t2=TO_VERSION --caption=$caption $localwinpath $remotewinpath
"$diffmergewinpath" -t1=FROM_VERSION -t2=TO_VERSION --caption="$caption" "$localwinpath" "$remotewinpath"

diffmerge-merge.sh

#!/bin/sh
# Use SourceGear DiffMerge as mergetool for git in cygwin.
#   git config --global mergetool.diffmerge.cmd "diffmergetool.sh \"\$LOCAL\" \"\$REMOTE\" \"\$BASE\" \"\$MERGED\""
#   git config --global mergetool.diffmerge.trustExitCode false
#   git mergetool -t diffmerge

# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf

library=githelperfunctions.sh

#[ -f $library ] && . $library
. $library

echo Launching DiffMerge.exe - diffmerge-merge.sh: 

set_path_vars "$1" "$2" "$3" "$4"

"$diffmergewinpath" --merge -t1=FROM_VERSION -t2=MERGED -t3=TO_VERSION --result="$mergedwinpath" --caption="$caption" "$localwinpath" "$basewinpath" "$remotewinpath"

unix2dos "$merged"

githelperfunctions.sh

# Helper functions


convert_path () {
    file=$1

    if [ "$file" == '/dev/null' ] || [ ! -e "$file" ]
        then 
           file="/tmp/nulla"
           `echo "">$file`
    fi
    echo `cygpath -w -a "$file"`
}


set_path_vars () {
    local=$1
    remote=$2
    base=$3
    merged=$4

    echo ========= Cygwin paths =======
    echo "LOCAL   :  $local"
    echo "REMOTE  :  $remote"
    echo "BASE    :  $base"
    echo "MERGED  :  $merged"

    localwinpath=$(convert_path "$local")
    remotewinpath=$(convert_path "$remote")
    basewinpath=$(convert_path "$base")
    mergedwinpath=$(convert_path "$merged")

    echo ========= Win paths =======
    echo "LOCAL   :  $localwinpath"
    echo "REMOTE  :  $remotewinpath"
    echo "BASE    :  $basewinpath"
    echo "MERGED  :  $mergedwinpath"

    caption=`basename "$merged"`
    diffmergewinpath="C:/Program Files/SourceGear/DiffMerge/DiffMerge.exe"
    winmergewinpath="C:/Program Files/WinMerge/WinMergeU.exe"
#   diffmergewinpath=`cygpath -u C:/Program Files/SourceGear/DiffMerge/DiffMerge.exe`
#   winmergewinpath=`cygpath -u \"C:\Program Files\WinMerge\WinMergeU.exe\"`
}

winmerge-diff.sh

#!/bin/sh
# Use winmerge as mergetool for git in cygwin.
#   git config --global difftool.winmerge.cmd "winmerge-diff.sh \"\$LOCAL\" \"\$REMOTE\" \"\$BASE\""
#   git config --global mergetool.winmerge.trustExitCode false
#   git difftool -t winmerge branch1..branch2   

# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf
# Reference: http://winmerge.org/docs/manual/CommandLine.html


library=githelperfunctions.sh

#[ -f $library ] && . $library
. $library

echo Launching winmerge.exe - winmerge-diff.sh: 

set_path_vars "$1" "$2" "$3" "$4"

"$winmergewinpath" /dl "LOCAL.$caption" /dr "TO_VERSION.$caption" "$localwinpath" "$remotewinpath" 

winmerge-merge.sh

#!/bin/sh
# Use winmerge as mergetool for git in cygwin.
#   git config --global mergetool.winmerge.cmd "winmerge-merge.sh \"\$LOCAL\" \"\$REMOTE\" \"\$BASE\" \"\$MERGED\""
#   git config --global mergetool.winmerge.trustExitCode false
#   git mergetool -t diffmerge

# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf
# Reference: http://winmerge.org/docs/manual/CommandLine.html

library=githelperfunctions.sh

#[ -f $library ] && . $library
. $library

echo Launching winmerge.exe - winmerge-merge.sh: 


set_path_vars "$1" "$2" "$3" "$4"

# -- use WinMergeU conflictFile
"$winmergewinpath" "$mergedwinpath"

For cygwin, the SO question "How can I configure Mercurial to use WinMerge for merges, under cygwin?" can be applied to git (when combining the following winmerge script with the older question "use Winmerge inside of Git to file diff")

#!/bin/sh
"/cygdrive/c/Program Files/WinMerge/WinMergeU.EXE" /e /ub /dl other /dr local `cygpath -aw $1` `cygpath -aw $2` `cygpath -aw $3`

Process

You have more details in this article "Git + WinMerge + Cygwin" (from Thiru Thirunavukarasu):
(but I would still recommend the WinMergeU.exe options from above)

Add the following lines to your .gitconfig file:

  [diff]
    tool = winmerge
  [difftool "winmerge"]
    cmd = git-difftool-winmerge-wrapper.sh \"$LOCAL\" \"$REMOTE\"
  [difftool]
    prompt = false

The last option (prompt = false) is optional. You can omit it if you do want Git to prompt you before opening each diff.

Create a file named git-difftool-winmerge-wrapper.sh and place it in your path.
I just dropped it in my home directory. You can change the default Cygwin path to include your home directory by modifying the .bash_profile file (also in your home directory) and adding PATH=${PATH}:${HOME}

Add the following to git-difftool-winmerge-wrapper.sh:

  #!/bin/sh
  echo "Launching WinMergeU.exe \"$(cygpath -aw "$1")\" \"$(cygpath -aw "$2")\""
  if [ -f "$1" -a -f "$2" ]
  then
    "C:/Program Files (x86)/WinMerge/WinMergeU.exe" -e -u -wl -dl "Base" -dr "Mine" "$(cygpath -aw "$1")" "$(cygpath -aw "$2")"
  else
    echo "skipping as one file doesn't exist"
  fi

(again, do some testing with those WinMerge options)


Scripts

If you want to go "all WinMerge", both for diff and merge git functions, you have this gist page to follow from ecerulm (Ruben Laguna):

diffmerge-diff.sh

#!/bin/sh
# Use SourceGear DiffMerge as mergetool for git in cygwin.
#   git config --global mergetool.diffmerge.cmd "diffmergetool.sh \"\$LOCAL\" \"\$REMOTE\" \"\$BASE\" \"\$MERGED\""
#   git config --global mergetool.diffmerge.trustExitCode false
#   git difftool -t diffmerge branch1..branch2

# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf

library=githelperfunctions.sh

#[ -f $library ] && . $library
. $library

echo Launching DiffMerge.exe - diffmerge-diff.sh: 

set_path_vars "$1" "$2" "$3" "$4"

echo "$diffmergewinpath" -t1=FROM_VERSION -t2=TO_VERSION --caption=$caption $localwinpath $remotewinpath
"$diffmergewinpath" -t1=FROM_VERSION -t2=TO_VERSION --caption="$caption" "$localwinpath" "$remotewinpath"

diffmerge-merge.sh

#!/bin/sh
# Use SourceGear DiffMerge as mergetool for git in cygwin.
#   git config --global mergetool.diffmerge.cmd "diffmergetool.sh \"\$LOCAL\" \"\$REMOTE\" \"\$BASE\" \"\$MERGED\""
#   git config --global mergetool.diffmerge.trustExitCode false
#   git mergetool -t diffmerge

# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf

library=githelperfunctions.sh

#[ -f $library ] && . $library
. $library

echo Launching DiffMerge.exe - diffmerge-merge.sh: 

set_path_vars "$1" "$2" "$3" "$4"

"$diffmergewinpath" --merge -t1=FROM_VERSION -t2=MERGED -t3=TO_VERSION --result="$mergedwinpath" --caption="$caption" "$localwinpath" "$basewinpath" "$remotewinpath"

unix2dos "$merged"

githelperfunctions.sh

# Helper functions


convert_path () {
    file=$1

    if [ "$file" == '/dev/null' ] || [ ! -e "$file" ]
        then 
           file="/tmp/nulla"
           `echo "">$file`
    fi
    echo `cygpath -w -a "$file"`
}


set_path_vars () {
    local=$1
    remote=$2
    base=$3
    merged=$4

    echo ========= Cygwin paths =======
    echo "LOCAL   :  $local"
    echo "REMOTE  :  $remote"
    echo "BASE    :  $base"
    echo "MERGED  :  $merged"

    localwinpath=$(convert_path "$local")
    remotewinpath=$(convert_path "$remote")
    basewinpath=$(convert_path "$base")
    mergedwinpath=$(convert_path "$merged")

    echo ========= Win paths =======
    echo "LOCAL   :  $localwinpath"
    echo "REMOTE  :  $remotewinpath"
    echo "BASE    :  $basewinpath"
    echo "MERGED  :  $mergedwinpath"

    caption=`basename "$merged"`
    diffmergewinpath="C:/Program Files/SourceGear/DiffMerge/DiffMerge.exe"
    winmergewinpath="C:/Program Files/WinMerge/WinMergeU.exe"
#   diffmergewinpath=`cygpath -u C:/Program Files/SourceGear/DiffMerge/DiffMerge.exe`
#   winmergewinpath=`cygpath -u \"C:\Program Files\WinMerge\WinMergeU.exe\"`
}

winmerge-diff.sh

#!/bin/sh
# Use winmerge as mergetool for git in cygwin.
#   git config --global difftool.winmerge.cmd "winmerge-diff.sh \"\$LOCAL\" \"\$REMOTE\" \"\$BASE\""
#   git config --global mergetool.winmerge.trustExitCode false
#   git difftool -t winmerge branch1..branch2   

# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf
# Reference: http://winmerge.org/docs/manual/CommandLine.html


library=githelperfunctions.sh

#[ -f $library ] && . $library
. $library

echo Launching winmerge.exe - winmerge-diff.sh: 

set_path_vars "$1" "$2" "$3" "$4"

"$winmergewinpath" /dl "LOCAL.$caption" /dr "TO_VERSION.$caption" "$localwinpath" "$remotewinpath" 

winmerge-merge.sh

#!/bin/sh
# Use winmerge as mergetool for git in cygwin.
#   git config --global mergetool.winmerge.cmd "winmerge-merge.sh \"\$LOCAL\" \"\$REMOTE\" \"\$BASE\" \"\$MERGED\""
#   git config --global mergetool.winmerge.trustExitCode false
#   git mergetool -t diffmerge

# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf
# Reference: http://winmerge.org/docs/manual/CommandLine.html

library=githelperfunctions.sh

#[ -f $library ] && . $library
. $library

echo Launching winmerge.exe - winmerge-merge.sh: 


set_path_vars "$1" "$2" "$3" "$4"

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