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

mergetool: what to do about deleting precious files?

From
Philip Oakley <philipoakley@iee.org>
Date
May 27, 2017, 10:03 UTC
Message-ID
<8CEDDC40C7D24404976929CF3E7AF6FC@PhilipOakley>

The git book [1] and a few blog posts [2] show how to preserve files which are in the current branch against changes that are on the branch being merged in.

e.g. (from [2])

echo '<filemane> merge=ours' >> .gitattributes && # commit git config --global merge.ours.driver true

(test) $ git checkout demo (demo) $ git merge - # <filename> contents are not merged and the original retained.

However what is not covered (at least in the documentation ) is the case where the file to be ignored is not present on the current branch, but is present on the branch to be merged in.

Normal expectations would be that in such a case the new file from the second parent branch would be added to the current branch.

Is there an easy way to use the current mergedriver mechanism to make this new file from the second parent 'go away' - does one have to delete output path (%P) or what? (or is this just a documenation issue?) [3]

Inspired by SO Q&A https://stackoverflow.com/questions/44131926/git-merge-remove-unnecessary-file-folder/44138354#44138354 " git merge I'm trying to merge my dev branch to master, but I don't want to merge some of the files/folders to master branch, because it is not needed now on Master."

Any suggestions for a simple merge driver to avoid merging and commiting such precious files from the second parent at merge time? -- Philip

[1] http://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#Merge-Strategies [2] https://medium.com/@porteneuve/how-to-make-git-preserve-specific-files-while-merging-18c92343826b [3] https://git-scm.com/docs/gitattributes #Defining a custom merge driver: "The merge driver can learn the pathname in which the merged result will be stored via placeholder %P."

Next: Junio C Hamano
Message 1 of 8 in “mergetool: what to do about deleting precious files?”
  1. Philip OakleyMay 27, 2017
  2. Junio C HamanoMay 28, 2017
  3. Philip OakleyMay 28, 2017
  4. Junio C HamanoMay 28, 2017
  5. Philip OakleyMay 29, 2017
  6. Junio C HamanoMay 30, 2017
  7. Philip OakleyMay 30, 2017
  8. Junio C HamanoMay 31, 2017

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.