2

We have 2 git branches - master and dev. The master contains files to be deployed to production and dev contains only files that needs modification.

At any point of time the master git branch will have 10+ files where as the dev will have only 1.

Now, the problem is if we merge master from dev it deletes all files and keeps only the 1 file that is available in the dev branch.

What we are looking for is to leave untouched all files from master and update only 1 file from dev (similar to rsync).

Any idea how we can implement delta merge in git?

Khilesh Chauhan
  • 739
  • 1
  • 10
  • 36

2 Answers2

2

It seems that dev had all the files, and later at some time only 1 file was kept while others were deleted.

When you want to apply commits from dev to master, you can use git cherry-pick ${commit_from_dev}.

If you intend to use git merge, from the beginning, you should have created dev as an orphan branch. In other words, dev should share no history with master when it's created.

# at the point of creating dev
git checkout --orphan dev master
git rm ${unwanted_files}
git commit -m 'init dev'

# the first time to merge dev
git checkout master
git merge dev --allow-unrelated-histories
ElpieKay
  • 27,194
  • 6
  • 32
  • 53
0

Create a new branch from local master then checkout the file to dev branch

$ git checkout master    # checkout master
$ git checkout -b dev2   # checkout new branch called 'dev2' with master history

$ git checkout dev -- <file-path> # checkout/update the file from 'dev' branch

Now, in dev2 branch you have

untouch all files from master and update only 1 file from dev

Sajib Khan
  • 22,878
  • 9
  • 63
  • 73