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

Can git tell me which uncommitted files clash with the incoming changes?

From
Mark Kharitonov <mark.kharitonov@gmail.com>
Date
Dec 17, 2018, 13:08 UTC
Message-ID
<CAG2YSPzmN5u1uAPVbjsqC3LzVVinFR21-_6wfrkBHdPWhOfMfQ@mail.gmail.com>

Hi, I have asked this question on SO (https://stackoverflow.com/questions/53679167/can-git-tell-me-which-uncommitted-files-clash-with-the-incoming-changes) and usually there are tons of responses on Git questions, but not on this one.

Allow me to quote it now.
Please, observe:
    C:\Dayforce\test [master ↓2 +0 ~2 -0 !]> git pull
    error: Your local changes to the following files would be
overwritten by merge:
            2.txt
    Please commit your changes or stash them before you merge.
    Aborting
    Updating 2dc8bd0..ea343f8
    C:\Dayforce\test [master ↓2 +0 ~2 -0 !]>

Does git have a command that can tell me which uncommitted files cause the this error? I can see them displayed by git pull, but I really do not want to parse git pull output.

I am fully aware of `pull.rebase` and `rebase.autostash` config options, please do not bring them up.

**EDIT 1**

It is OK to execute `git pull` first. In fact, the logic to identify the problematic files will be done after `git pull` fails with this reason. The way I recognize it in Powershell is:

    git pull
    # Possible exit codes:
    # 1 - either local changes or pull merge conflict (but the merge
has not been started yet)
    # 128 - a merge is in progress
    if ($LASTEXITCODE)
    {
        git merge HEAD 2> $null                      # Disambiguate
the exit code
        if ($LASTEXITCODE -eq 128)
        {
            # Two options:
            #  - pull merge conflict
            #  - a merge is in progress
            git mergetool
        }
        else
        {
            throw "Cannot pull due to uncommitted changes"
        }
    }

So, instead of aborting I would like to identify the problematic files and essentially replicate the `rebase.autostash`, but without `rebase`.

**EDIT 2**

I used to think that git pull outputs something like this in case of clashes with uncommitted changes:

    C:\xyz\test [master ↓4 ↑1 +0 ~3 -0 !]> git pull
    error: Your local changes to the following files would be
overwritten by merge:
            2.txt
            a.txt
    Please commit your changes or stash them before you merge.
    Aborting
    C:\xyz\test [master ↓4 ↑1 +0 ~3 -0 !]>
Which is easy to parse. But today, I got something different:
    C:\xyz\test [master ↓4 ↑1 +0 ~2 -0 | +0 ~1 -0 !]> git pull
    error: Your local changes to the following files would be
overwritten by merge:
      1.txt a.txt
    C:\xyz\test [master ↓4 ↑1 +0 ~2 -0 | +0 ~1 -0 !]>

I do not know if this has something to do with my Powershell console having gotten botched somehow or with some recent git update, which I had installed automatically without noticing it.

-- 
Be well and prosper.
==============================
"There are two kinds of people.Those whose guns are loaded and those who dig."
   ("The good, the bad and the ugly")
So let us drink for our guns always be loaded.
Next: Jeff King
Message 1 of 10 in “Can git tell me which uncommitted files clash with the incoming changes?”
  1. Mark KharitonovDec 17, 2018
  2. Jeff KingDec 17, 2018
  3. Ævar Arnfjörð BjarmasonDec 17, 2018
  4. Jeff KingDec 17, 2018
  5. Duy NguyenDec 17, 2018
  6. Elijah NewrenDec 17, 2018
  7. Duy NguyenDec 17, 2018
  8. Mark KharitonovDec 17, 2018
  9. Jeff KingDec 18, 2018
  10. Elijah NewrenDec 18, 2018

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.