1

We have the following branches in our project:

  • master
  • preproduction
  • production

We use branches like feature/myfeature-123 to develop new function. If they are done, we merge those into the master. After a while, when enough features are done and successfully merged into master, we deploy our project to preproduction. For this, we need to merge the latest changes into the preproduction branch.

Note: Nothing was changed in the preproduction branch in the meantime

And here is our problem: We face many merge-conflicts. Then i thought, okay. Lets fix it manually. I did the following:

  1. Checkout preproduction
  2. (Just to be safe) Pull the latest changes in this branch (There were none)
  3. Create a new branch from the current branch i am in. Name: deployment-april2019
  4. Switched to this new branch
  5. git pull origin master to get the current state from master into this branch.

As stated above, we face a lot of merge conflicts. Since we changed nothing in the preproduction branch, i wanted to accept all changes that were done in the master branch. This should fix all conflicts.

This worked, BUT in the master branch we deleted several files / lines that were also in the preproduction branch. I would have expected, that those deleted files / deleted lines would also be applied to the preproduction branch. But this was not the case. They stayed in the preproduction branch. Any ideas what to do, to solve this?

I am not the biggest expert in this. I have a general understanding of Git, but i am still afraid of breaking things by executing the wrong commands. I thought if rebase could help here, but i dont know.

I am very thankful for any help you can provide.

Biffen
  • 6,249
  • 6
  • 28
  • 36
Max Schindler
  • 380
  • 2
  • 17
  • Before the merge, is `preproduction` behind `master` or diverged? You can check with `git branch --contain preproduction`, if `master is listed, `preproduction` is behind. – padawin Apr 03 '19 at 12:00
  • The deleted files are still part of the branch? Or are they just still hanging around in the folder? – kowsky Apr 03 '19 at 12:20
  • @padawin: yes ... preproduction is 321 behind and 9 ahead. I think those 9 ahead, come from earlier deployments to preproduction, where new commits / merge requests where applied to preproduction, but not to master. – Max Schindler Apr 03 '19 at 12:41
  • @kowsky: I dont understand the question right i guess. But i try to explain it more clear: In master and preproduction there is a file called UserService. This was deleted now in master, since we dont need it anymore. When i pulled the master into my deployment-april-2019 branch, the file was still there. In other words, i did not get deleted. – Max Schindler Apr 03 '19 at 12:43
  • @MaxSchindler if you are sure that master is newer and preprod is behind, my suggestion should work for your example. – nmanh Apr 03 '19 at 13:43

2 Answers2

0

If you are sure, that master is the source of truth and is kind of a fast-forward (!). You could just merge while accepting from Master. This then can be done by a job f.e. in Jenkins/Travis/CI.

Add the -X option to theirs. For example:

git fetch --all  --prune
git checkout preproduction
git merge -X theirs origin master

Everything will merge in the desired way.

Is there a "theirs" version of "git merge -s ours"?

The advantage with this approach is, that you still preserve the commit history.

nmanh
  • 325
  • 2
  • 14
0

It might be good to bring back preproduction up to track with master. You can do the following:

git log --oneline master..preproduction

To list the 9 commits in preproduction only.

Then, reset preproduction at the state of master:

git checkout preproduction
git reset --hard master

Finally, add back to preproduction any of the 9 commits listed above that you are interested in with:

git cherry-pick <commit-hash>

You will then have to force push back preproduction as it will have diverged from the origin.

That will bring it up to track with master. Ideally though, you will want no commit in preproduction only, to it can be easy to push it with a latest master in the future.

padawin
  • 4,230
  • 15
  • 19