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

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

From
Jeff King <peff@peff.net>
Date
Dec 17, 2018, 16:21 UTC
Message-ID
<20181217162108.GB914@sigill.intra.peff.net>
In-Reply-To
<CAG2YSPzmN5u1uAPVbjsqC3LzVVinFR21-_6wfrkBHdPWhOfMfQ@mail.gmail.com>
On Mon, Dec 17, 2018 at 08:08:49AM -0500, Mark Kharitonov wrote:
Show 12 quoted lines
>     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.

That message is generated by merge-recursive, I believe after it's figured out which files would need to be touched.

I don't offhand know of a way to get that _exact_ answer from another plumbing command. But in practice it would probably be reasonable to ask for the diff between your current branch and what you plan to merge, and cross-reference that with the list of files with local changes.

Something like:
  git pull ;# this fails, but FETCH_HEAD is left over
  git diff-tree -z --name-only HEAD FETCH_HEAD >one
  git diff-index -z --name-only HEAD >two
  comm -z -12 one two

would work on Linux, but "comm -z" is not portable (and I suspect you may not have comm at all on Windows). You can probably find a way to show the common elements of the two lists using the scripting language of your choice.

The answer that gives will be overly broad (e.g., in a case where our local branch had touched file "foo" but other side had not, we'd consider "foo" as a difference the two-point diff-tree, whereas a real 3-way merge would realize that we'd keep our version of "foo"). But it might be good enough for your purposes.

-Peff
Previous: Mark KharitonovNext: Ævar Arnfjörð Bjarmason
Message 2 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.