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

partial stash, reversed-merge, and file modifications

From
SMStefan Monnier <monnier@iro.umontreal.ca>
Date
Aug 12, 2015, 20:05 UTC
Message-ID
<jwvr3n8xptl.fsf-monnier+gmane.comp.version-control.git@gnu.org>

I'm pretty happy about Git in general, but for two situations where I've found workarounds, which both have the same problem, which is that they "touch" files unnecessarily:

* First case: merge into a dirty tree.

I often want to "git pull" into a tree that's dirty. I know many people find this to be heresy, but for various reasons, I have a few trees that are pretty much always dirty and where I want to pull anyway without ever wanting to commit those changes.

The simplest solution I found is:
  git stash; git merge --ff-only; git stash apply; git stash drop

Problem with it: this will needlessly "touch" all the files which are locally modified but aren't affected by the merge. So a subsequent "make" can easily end up taking a lot more time than needed.

A simple solution to this problem would be to only stash those files which conflict:

  git stash save --only-some-files $(git merge 2>&1 | sed -ne 's/^	//p')
  git merge --ff-only; git stash apply; git stash drop

but of course the "--only-some-files" option to "stash save" doesn't exist. And writing an equivalent script is pretty painful.

* Second case: merge with reversed parents

The order of parents in a merge is sometimes important. Say you're in your branch "newfeature" and you want to install it into "master", you could do it this way:

   git merge master; <..make; check; push..>

but that gives you a history where the first parent is your feature branch and all the changes made to master in the mean time look like secondary changes. This is probably OK seen from "newfeature" but if you push this to "master", it will look odd on "master".

So instead, you'll want to do what I call a "reversed merge":
  git checkout master; git merge newfeature; <..make; check; push..>

Now the history tree is right. Good. But beside it being sightly more cumbersome, the main problem with it is that, again, this will needlessly "touch" all those files that are modified by "newfeature" but not by "master" (compared to the ancestor). So again, the subsequent "make" can take a lot more time than needed.

I'd love to either hear about ways to avoid/reduce this problem with current Git, or else to see some new features added to Git to reduce/solve those problems.

        Stefan
Message 1 of 1 in “partial stash, reversed-merge, and file modifications”
  1. Stefan MonnierAug 12, 2015

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.