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

Re: can I always ignore a file during a merge?

From
Jeff King <peff@peff.net>
Date
Jul 3, 2012, 07:38 UTC
Message-ID
<20120703073847.GD16679@sigill.intra.peff.net>
In-Reply-To
<p06240817cc114629c20f@[192.168.1.122]>
On Wed, Jun 27, 2012 at 07:39:03PM -0400, Stephen Bannasch wrote:
> Is there a way to merge from branchA to branchB and from branchB to
> branchA while completely ignoring changes to a file that is tracked
> and exists in both branches?

No. Fundamentally, a commit object in git consists of a content state (i.e., a pointer to a tree object) and a pointer to all previous history (i.e., zero or more "parent" pointers to commit objects). The semantics of a commit object can be thought of as "I have looked at all of the history in all of the parent commits, and the state contained in my tree pointer supersedes them all".

So you could make merge B into A, but keep A's copy of the file (e.g., using the "ours" strategy). But that is saying that you considered the state of both A and B, and decided that A's version supersedes what happened in B. If you later wanted to merge from A to B, B's version of the file would not even be considered as an outcome for the merge.

There isn't really a clever way to work around this via a different merge strategy; it's a fundamental aspect of git's data structure for storing history.

-Peff
Previous: Stephen BannaschNext: Philip Oakley
Message 2 of 3 in “can I always ignore a file during a merge?”
  1. Stephen BannaschJun 27, 2012
  2. Jeff KingJul 3, 2012
  3. Philip OakleyJul 5, 2012

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.