git - Have two different copies of same file in two different branches -


do know how have 2 different copies of same file in 2 different branches in git?

let assume have file called config.
i'm trying achieve have copy of file in dev branch different in master branch.

the important thing file can't ignored in gitignored.

you can checkout 2 branches. modify file , commit them each branch.

if want merge branches , have 2 separate files (different content) in each branch, commit changed branches , set desired file tin .gitattributed grab ours file - result in file never overwritten

read , set here:
https://git-scm.com/book/en/v2/customizing-git-git-attributes#merge-strategies

you can use git attributes tell git use different merge strategies specific files in project.

one useful option tell git not try merge specific files when have conflicts, rather use side of merge on else’s.

this helpful if branch in project has diverged or specialized, want able merge changes in it, and want ignore files.

config_file merge=ours 

as @torec mentioned in comment:

beware of consider bug in git: if git able trivially merge file not run custom merge driver. git tries simple 2-way merge first, before attempting 3-way merge

so option use smudge/clear filter make sure have right file.

smudge

read , set here:
https://git-scm.com/book/en/v2/customizing-git-git-attributes

it turns out can write own filters doing substitutions in files on commit/checkout.

these called clean , smudge filters.

in .gitattributes file, can set filter particular paths , set scripts process files before they’re checked out (“smudge”, see figure 8-2) , before they’re staged (“clean”, see figure 8-3).

these filters can set sorts of fun things.

enter image description here


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -