I\'m trying to keep 2 projects of website in one repository. This websites are mainly the same except template (html,css) files and few config files. The main site (which is
As mention in my answer on merge drivers, they are useful in case of conflict only.
That applies to a merge=ours in a .gitattributes file: see Merge strategies.
One very useful option is to tell Git to not try to merge specific files when they have conflicts, but rather to use your side of the merge over someone else’s.
This recent thread (2012) confirms it:
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
intoA
, but keepA
'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 thatA
's version supersedes what happened inB
. If you later wanted to merge fromA
toB
,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.
If those templates are in a sub-directory, it is best to isolate them in a git repo of their own, in order to include that repo as a submodule.
If not, then you need to revert the files incorrectly merged before committing (as in this thread):
git merge --no-commit other
git checkout HEAD XYZ # or 'git rm XYZ' if XYZ does not exist on master
git commit