I'd like to compare two files, one file is in another branch and the other is the uncommitted version of the same file in the current branch. So I do :
git difftool other_branch_name file_to_compare
now I want to edit uncommitted version in the current branch but I can't because vimdiff is opened in read-only mode...
So what's the solution to use git difftool and allow modification ?
I don't know the specific commands necessary to invoke vimdiff so that the uncommitted file is opened in write mode, but in general, git does in fact have configuration settings that you can use to set up how your difftool if invoked when you use git difftool
. See the difftool.<tool>.cmd
setting in the git difftool doc and the git config doc:
difftool.<tool>.cmd
Specify the command to invoke the specified diff tool. The specified command is evaluated in shell with the following variables available:
$LOCAL
is set to the name of the temporary file containing the contents of the diff pre-image and$REMOTE
is set to the name of the temporary file containing the contents of the diff post-image.
So you could do something like this to configure your difftool:
$ git config --global difftool.myDifftool.cmd \
"myDifftool --read-only-flag $LOCAL --editable-flag $REMOTE"
Based on the link to Vimdiff multiple windows different read/write permission that mah posted, I guess you could configure difftool
for vimdiff this way, but I'm not sure if the vimdiff options are actually correct:
$ git config --global difftool.vimdiff.cmd \
"vimdiff -R $LOCAL -c ':se noreadonly' $REMOTE"