'Procedure for developing on top of feature branch when original feature branch is merged with a squash

It's not that uncommon when I find myself:

  • needing to work on the next feature
  • before the latest work is integrated to the main branch
  • and new work requires code from the previous branch
  • and the merge into main is a squash.

When this happens, merging is painful.

The scenario:

git checkout develop
git checkout -b feature/A

git commit -am "A1" 
git commit -am "A2" 

git push // + start a pull request

//Before the pull request is finished 

git checkout -b feature/B
git commit -am "B1" 

// Pull request is accepted and merged as a squash

// Other pull requests 

git fetch origin develop
git merge origin/develop
(conflicts)

Now:

  • feature/B has A1, A2, B1
  • and develop has a commit D1 that has the changes from A1 and A2
  • and git cannot know that D1 is A1+A2
  • and it rightly marks places where feature/B touches code changed by feature/A as conflicts.

Ideally I would love to be able to:

  1. not have conflicts where what's coming in from develop to feature/B came from feature/A and
  2. have conflicts if the change came from another branch (or not from commits A1 and A2.

Is that possible?

git


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source