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 my say Supersite) is in branch master. The second site is in branch secondarySite. Every time, when I develop some new feature in master branch I want to merge it to secondarySite but I want to exclude templates files from merging.
I found partial solution here How do I tell git to always select my local version for conflicted merges on a specific file? but it works only when I change template file in both branches and conflict occurs. When there is no conflict git just use newer remote version of file.
How can I tell git to always leave specified local files unchanged even if there is no conflict.
Or maybe I use totally wrong approach to the problem?
Thanks in advance for any help.
git checkout staging # go to staging branch git checkout dev . # this checkout dev file changes into staging git reset HEAD build # this remove added file in build folder git clean -f # this drops untracked files we just reseted git checkout -- .
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
Here git-update-index - Register file contents in the working tree to the index.
git update-index --assume-unchanged <PATH_OF_THE_FILE>
Example:-
git update-index --assume-unchanged somelocation/pom.xml
or
Add file paths in .gitignore
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With