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

Re: git pull suggestion

From
AAghiles <aghilesk@gmail.com>
Date
Apr 9, 2010, 19:33 UTC
Message-ID
<i2y3abd05a91004091233nc11ee5f8m4f40e7451e02518a@mail.gmail.com>
In-Reply-To
<20100409034911.GA4020@coredump.intra.peff.net>
Jeff King <peff@peff.net> wrote:
Show 22 quoted lines
>
> ...
>
> I get:
>
>  $ git merge other
>  error: Your local changes to 'file1' would be overwritten by merge. Aborting.
>  Please, commit your changes or stash them before you can merge.
>
> But that's not the whole story. Once you fix that, you will see that
> your local changes to 'file2' would be overwritten by the merge:
>
>  $ git commit -m "commit file1" file1
>  $ git merge other
>  error: Your local changes to 'file2' would be overwritten by merge. Aborting.
>  Please, commit your changes or stash them before you can merge.
>
> And so on.
>
> Notice that I didn't use "pull", but pull should invoke git-merge after
> fetching from the remote. I assume this is the same message you are
> talking about?
Exactly.
Show 14 quoted lines
> It is possible to manually get the answer you want, or close to it. You
> are looking for the intersection of files modified by you and files
> modified by the upstream. So:
>
>  # unique list of modified working tree files and index entries
>  $ (git diff-files --name-only;
>     git diff-index --name-only HEAD
>    ) | sort -u >us
>  # files that will be changing as part of merge
>  $ git diff-tree --name-only $HEAD_TO_MERGE_FROM | sort >them
>  $ comm -12 us them
>
> where $HEAD_TO_MERGE_FROM in my example would be "other", but in the
> case of a pull, would probably be FETCH_HEAD.
Thanks a lot for this, I will try it.
Show 22 quoted lines
> In practice, I have never actually wanted to this. The workflow goes
> something like:
>
>  (1) Run git merge foo (or git pull)
>
>  (2) Oops, I have cruft in my working tree. What was it? Run git
>      status.
>
>  (3a) Oh, that cruft should have been committed. Make a commit (or
>       commits). Go to (1), possibly still with some changes in
>       the working tree.
>
>       or
>
>  (3b) Oh, that cruft is some change I want to carry forward in the
>       working directory. Run git stash, repeat the pull, fix any
>       merge conflicts, and then git stash apply.
>
> So it doesn't really matter to me if there is 1 conflicting file or 100.
> In most cases, the commits in (3a) will clean up all of it in one go.
> Otherwise, I'll just stash it all and come back to it.
>

That is exactly my workflow and I am perfectly happy with that. The problem is that I am putting git in the hands of svnites and sometimes I have to address some usability issues like these.

It is another issue, but I feel that the 'dirty working directory' is one of the major usability hurdles for people migrating from svn and CVS (a git pull --merge-using-stash could address it, maybe).

  -- aghiles
Previous: Jeff KingNext: Jeff King
Message 7 of 15 in “git pull suggestion”
  1. AghilesApr 7, 2010
  2. Thomas RastApr 8, 2010
  3. AghilesApr 8, 2010
  4. Nicolas SebrechtApr 8, 2010
  5. AghilesApr 9, 2010
  6. Jeff KingApr 9, 2010
  7. AghilesApr 9, 2010
  8. Jeff KingApr 10, 2010
  9. Junio C HamanoApr 10, 2010
  10. AghilesApr 11, 2010
  11. Junio C HamanoApr 11, 2010
  12. Matthieu MoyApr 11, 2010
  13. AghilesApr 12, 2010
  14. Junio C HamanoApr 12, 2010
  15. AghilesApr 9, 2010

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.