git-mergetool–lib - Linux


Overview

git-mergetool–lib is a library that provides support for launching external merge tools such as meld, kdiff3, vimdiff, etc. It is designed to be used by developers to integrate 3rd party merge tools into their own programs or applications.

Syntax

git-mergetool--lib [OPTIONS] [--] <TOOL>

Options/Flags

-m
: Path to the merge description file. The contents of the file should be in the format specified in the git-mergetool documentation.

-t
: Output the contents of the merge description file without invoking the tool.

–tool
: Specifies the merge tool to use instead of the one specified by the GIT_MERGE_TOOL environment variable.

Examples

Launch Meld as the merge tool

GIT_MERGE_TOOL=meld git mergetool

Output the contents of the merge description file

git mergetool --tool=meld -- -t

Common Issues

Mergetool not found
: The specified mergetool (specified by either the GIT_MERGE_TOOL environment variable or the --tool option) must be installed and in the PATH environment variable.

Integration

Calling git-mergetool–lib from C

#include <git2.h>

int main(int argc, char *argv[]) {
  git_mergetool_options mergetool_opts = GIT_MERGETOOL_OPTIONS_INIT;
  git_mergetool_exe mergetool_exe;

  git_mergetool_init_options(&mergetool_opts, MERGETOOL_DESCRIPTION);

  if (git_mergetool_set_path(&mergetool_exe, "/usr/bin/meld") < 0) {
    fprintf(stderr, "Failed to set mergetool path\n");
    return 1;
  }

  git_mergetool_exe_free(&mergetool_exe);
  git_mergetool_options_free(&mergetool_opts);

  return 0;
}

Related Commands