Home > Uncategorized > Git on Windows

Git on Windows

One of the problems with using git on Windows is that it’s difficult to integrate it with other native (Windows) tools. That’s because the environment git runs in (cygwin or msysgit) refers to files by their UNIX name, but the Windows tools have no notion of where /tmp is for example (and that location can be different between cygwin and msysgit).

When doing an interactive rebase, the editor might be asked to edit a file such as /cygdrive/c/some/path/to/a/file. When doing a diff in git, one or both of the files to be diff’d might be placed by git in /tmp. Windows tools don’t understand such path names.

Fortunately, cygwin ships with a utility called cygpath that can be used to convert between UNIX and Windows paths. Msysgit doesn’t have this utility, but if cygwin’s /bin directory is in your Windows path, msysgit will pick it up and the scripts below will be usable for both cygwin and msysgit.

Here’s a GitEditor.sh script that can be used as a wrapper around your editor:

#!/bin/sh

# Author: Gabriel Burca
#
# Script arguments:
# file-to-edit

FILE=`cygpath -w "${1}"`
"C:/Program Files/Vim/vim72/gvim.exe" "$FILE"
This GitExtDiff.sh script can be used as a wrapper around your diff tool:
#!/bin/sh

# Author: Gabriel Burca
#
# Script arguments:
# path old-file old-hex old-mode new-file new-hex new-mode

# The old-file path is typically "/tmp/.diff_something" and windows programs
# don't know how to get to "/tmp"
# We use cygpath to convert to something windows programs understand.

OLD_FILE=`cygpath -w "${2}"`
NEW_FILE=`cygpath -w "${5}"`
"C:/Program Files/WinMerge/WinMergeU.exe" -e -ub "$OLD_FILE" "$NEW_FILE"
Finally, you'll need to modify ~/.gitconfig to use these scripts by adding something like this to it:
[diff]
external = "C:/Utility/GitExtDiff.sh"
[core]
editor = "C:/Utility/GitEditor.sh"
Categories: Uncategorized Tags: , , , ,
  1. No comments yet.
  1. No trackbacks yet.