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

Re: Request for adding a simple mechanism to exclude files from Git merge operation

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jun 22, 2020, 19:41 UTC
Message-ID
<20200622194122.GN6531@camp.crustytoothpaste.net>
In-Reply-To
<DM6PR11MB27958B80E3994CEEF13971ECE5990@DM6PR11MB2795.namprd11.prod.outlook.com>
On 2020-06-20 at 18:21:40, Tiran Meltser wrote:
> Hi,
> This topic is quite common in various use cases (e.g. production configuration vs. staging one) and there are quite a few talks about it in the web.
> Nevertheless, there is no specific solution to this problem, only partial workarounds (including the famous merge driver “ours”).

In general, this is a hard problem. When you perform a merge, you're asking to incorporate changes from both heads against a common merge base. What does it mean when you want to merge two branches together but not make any changes? Which version do you want, ours or theirs? Normally merges are symmetric, so if you want non-symmetric behavior, you have to define what it's supposed to be.

In addition, it's probably not the case that you want _never_ to modify the contents of a file on a merge. For example, if you have a feature branch to update the production configuration to fix an issue or add a new option, you probably do very much want that merge to succeed and not be a no-op, so a configuration in .gitattributes may not be helpful for your use case.

Because this is such a tricky problem and there usually isn't a consistent set of behavior that people _always_ want to apply (unlike, say, line endings), the general recommendation here is that folks just avoid this problem altogether. For example, your repository can contain configs for development, production, and staging and a script can copy the appropriate one into place based on an environment variable or hostname.

-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Previous: Tiran MeltserNext: Sergey Organov
Message 4 of 16 in “Request for adding a simple mechanism to exclude files from Git merge operation”
  1. Tiran MeltserJun 20, 2020
  2. Philip OakleyJun 21, 2020
  3. Tiran MeltserJun 22, 2020
  4. brian m. carlsonJun 22, 2020
  5. Sergey OrganovJun 23, 2020
  6. Philip OakleyJun 23, 2020
  7. Sergey OrganovJun 23, 2020
  8. Elijah NewrenJun 23, 2020
  9. Sergey OrganovJun 23, 2020
  10. Elijah NewrenJun 23, 2020
  11. Chris TorekJun 23, 2020
  12. Sergey OrganovJun 24, 2020
  13. Junio C HamanoJun 23, 2020
  14. Sergey OrganovJun 24, 2020
  15. Junio C HamanoJun 24, 2020
  16. Sergey OrganovJun 25, 2020

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.