git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Interpreting git merge failures

From
SBScott Bronson <bronson@rinspin.com>
Date
Jul 7, 2011, 18:45 UTC
Message-ID
<CAKmUPx5Qt2K+7F+BsW3WTmRjodBSrteuyG8p9oRHZuhApTu4+g@mail.gmail.com>

What is the best way to determine why a git merge failed? I'm writing a script that needs to do different things depending on what went wrong.

Right now I'm parsing error messages. It's obviously a bad idea and prone to breakage but it does work. Example:

    `git fetch origin #{tag || :master}`
    output = `git merge --ff-only FETCH_HEAD 2>&1`
    # warning, bad idea:
    if output =~ /Not possible to fast-forward/
      log "has different ancestry from upstream, removing and re-cloning."
      remove_and_reclone
    elsif msg =~ /You have unstaged changes/ ||
          msg =~ /Your local changes [a-z ]* would be overwritten/ ||
          msg =~ /commit your changes or stash them before you can merge/
      log "has unsaved changes, invalid doc/tags file in upstream repo?"
      work_around_tagsfile
    elsif msg =~ /untracked working tree files would be overwritten/
      log "has conflicting file, removing and re-cloning."
      abort  # don't blow away unknown file
    else
      log msg
      abort
    end

There's got to be a better way! I could special-case each check beforehand using git ls-files and friends but that seems almost as ugly... Hoping a smarter solution exists.

This is for https://github.com/bronson/vim-update-bundles
Thanks!
    - Scott
Next: Jeff King
Message 1 of 3 in “Interpreting git merge failures”
  1. Scott BronsonJul 7, 2011
  2. Jeff KingJul 12, 2011
  3. Junio C HamanoJul 12, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.