0

I know this question has been asked an answered many times, but I'm running into a weird issue that I haven't been able to find the answer to online.

I've created a branch and decided to open a PR. The problem is that Bitbucket is complaining that there are conflicts and that I need to manually resolve them first.

So I ran git pull origin develop in my current feature branch. I started manually resolving conflicts, but then I realized that some of the code that I wrote is gone. A simple example is I made changes to a function, so that the function takes an argument. But after running git pull origin develop, the function call stayed the same, (i.e somefunction(someParameter)), but the function definition went back to export const someFunction() instead of export const someFunction(someParameter).

I've also tried running git pull -s recursive -X ours origin develop, but that didn't fix the issue.

What am I doing wrong here? I want all the code on my feature branch to be the code that develop should have. Is it possible to completely override any changes on develop during a git pull origin develop?

I should probably also mention, that changes to develop can only be made with PRs, so I can't force push to it.

My only temporary solution is to copy all the contents of my directory (on my feature branch) over to a temporary directory, then checkout to develop, then checkout into a new branch and then delete the content in the directory and paste into it the content from the temporary directory. Obviously, I'd like to know if another way is possible, but I guess I'll do this for now.

Mike K
  • 7,621
  • 14
  • 60
  • 120
  • Your question subject mentions `master` but your question body mentions only `develop`. Personally I recommend *avoiding* `git pull` entirely: it runs `git fetch`, then it runs a second Git command. That *second* command is where all the grief and pain is found. I think it's better to use an explicit second command, so that you have more control over everything and understand precisely what you're doing. Meanwhile, you might want to have a look at my recent long answer [here](https://stackoverflow.com/q/66624110/1256452), as background on merging. – torek Mar 14 '21 at 14:59
  • I suspect, though, based on `git pull -s recursive -X ours origin develop`, that you might have `git pull` running `git rebase` as the second command. The `-X ours` option to rebase means *throw away my code*, so this would directly lead to your problem. That might not be the problem—I'm making a lot of assumptions—but if you said *I ran `git fetch`, then ran `git rebase`* or *then ran `git merge`* I'd be able to be more sure. – torek Mar 14 '21 at 15:06

1 Answers1

0

I think you are doing the steps wrong. Check this link What happens when I do git pull origin master in the develop branch?. Basically when you perform git pull origin develop you are pulling the develop branch to your feature branch I don't think this should be the way to resolve your conflicts.

There are 2 ways to solve this.

  1. If you are using github raise a PR. Then it should show conflicts and you should be able to resolve it.

  2. If you want to resolve it locally. Checkout to your develop branch and do a

git pull

After this checkout your feature branch and merge the develop branch to your feature branch

git merge develop

You should then be able to resolve your conflicts and this shouldn't remove any code from your feature branch (Unless it is something removed from develop branch)

Ritwik G
  • 406
  • 2
  • 8
  • My local version of `develop` is up to date with remote, so this wouldn't work. Also, pulling develop into my feature branch is exactly what I need to do. Then I'd have to resolve the conflicts and then push back to remote/feature-branch, before being able to merge feature-branch into develop. – Mike K Mar 14 '21 at 14:14
  • @MikeK What I am suggesting here is that you merge latest `develop` in to your `feature/branch` before you raise a PR for merging `feature/branch` in to `develop`. In the first step you should be able to resolve the conflicts manually. Hope my point is clear. – Ritwik G Mar 15 '21 at 05:39