1

I have three branches in the repository.

master
slave 1
slave 2

there is one package.json file. It should be different in each of the branches. But if I run the git merge master command. These two branches merge into one. How to exclude package.json from merging branches so that each branch has its own version?

add:

I have a sequence

git checkout slave 1 && git merge -Xtheirs --no-edit master && git push && git checkout master

enter image description here

mike
  • 1,233
  • 1
  • 15
  • 36
Sergey
  • 418
  • 1
  • 7
  • 21
  • Does this answer your question? [Ignore files that have already been committed to a Git repository](https://stackoverflow.com/questions/1139762/ignore-files-that-have-already-been-committed-to-a-git-repository) – fatemeh fallahi arezoudar May 28 '20 at 13:16
  • 1
    I don't think he is looking for that. He *wants* these files to be there yet not be merged. But again, it depends on him – rasengan__ May 28 '20 at 13:21

1 Answers1

2

There is no automatic way to tell git to avoid merging changes on a file. You can ask to check out the file from HEAD before finishing the merge:

git merge other-branch --no-commit
git checkout HEAD -- package.json # get the file back
git commit -m "Now we finish the merge"
eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • I am add info in question. What i want – Sergey May 28 '20 at 13:40
  • 1
    `--theirs` is only about conflicting stuff... not even _files_ but conflicting pieces of code. Again: there is no way to tell git to keep a file from merging.... you can get the file back before finishing it up, as I explained. – eftshift0 May 28 '20 at 13:47