git revert merge when merged back is deleting files

Viewed 747

Following are the branches in concern inn my project repo:

release/0.1.2 (012)
release/0.2.0 (020)

Following actions happened:

  1. Merge from 020 branches to 012 branch added some new files.

  2. That merge was reverted which therefore deleted some files.

  3. Some other commits were added in 012

PROBLEM:

But now when I am trying to merge 012 to 020, this merge is trying to delete the files in 020 (the ones which were deleted in 012 by the revert). These files are not expected to be deleted in 020.

Since the revert technically deleted the files, this merge is also trying to delete the file (assuming this to be a change).

Is there a way to achieve this merge which won't delete these files without manually saving those files (etc).

2 Answers

Merge with --no-commit, meaning to do the merge but not commit it. Then you can undo the deleted files with git restore. Once you've altered the merge to your liking, commit it.

Ok so After going through the advice in the answer and also following up through some other StackOverflow answers following is the best course of action taken in such scenarios:

  1. Find the revert commit (the one that caused the deletion of the files).
  2. Merge the commit before it to the new branch (020 in this scenario) git merge <commit-hash-of-the-commit-before-revert> .
  3. Merge the revert commit with 'ours' strategy (git merge -s ours <commit-hash-of-revert>)
  4. Merge the full branch (git merge 012)
Related