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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux