0

Just left Sourcetree and am now using terminal for git operations. I'm on my feature branch and I commit my changes from the last couple days. I push to remote.

I then run git rebase develop before i create my pull request to the develop branch. The rebase completes successfully, without merge conflicts or anything. I do nothing else except create the PR.

But my PR has other commits from other developers. Why is that? I'd expect that after a rebase that I'd only see my changes. Did I miss a step after running git rebase develop?

fumeng
  • 1,771
  • 5
  • 22
  • 61
  • Did you base your branch on develop, originally, or did you base it on someone else's yet-to-be merged work/branch? – Lasse V. Karlsen May 16 '22 at 19:07
  • I created it off of develop. – fumeng May 16 '22 at 19:16
  • 1
    If you created your branch from develop, only worked on it yourself, and then finally rebased it on top of develop without merge conflicts or anything strange, then the final merge back to develop **should not** include someone else's commits. There has to be something you're missing in your process here. – Lasse V. Karlsen May 16 '22 at 19:19
  • @LasseV.Karlsen - precisely. Can you confirm that after a successul rebase (without merge conflicts) that I don't have to do anything else? Like run git rebase develop and then git add . or push back to my remote before creating the PR? – fumeng May 16 '22 at 19:21
  • 1
    If everything you've explaind is correct, as in 1) you created your branch from develop, 2) nobody else committed to it, 3) you rebased your branch on top of develop and did not get any merge conflict, then I can confirm that you **should not** get any other developers commits listed as being part of your pull request. You do not have to add anything either, that branch should be ready to be merged to develop, and the only changes that should be listed are those from your branch. As I said, if you see other developers commits being listed, you did something other than what you described. – Lasse V. Karlsen May 16 '22 at 19:24
  • 1
    There are some missing steps. For example, you pushed, and then you rebased locally, and then created the PR. But the local rebase would have no effect unless you force pushed between rebasing and creating the PR. – TTT May 16 '22 at 20:30
  • Note my previous comment doesn't explain your issue though. Note this statement, "I'd expect that after a rebase that I'd only see my changes." isn't necessarily true. You should see only your changes regardless of whether or not you rebase. (Unless someone force-pushed `develop`.) – TTT May 16 '22 at 20:36
  • After some more research,I think what happened was that when I did a "git rebase develop" that my local ref for develop was out of sync with remote. maybe that was the problem. i guess before a rebase i need to switch to develop, do a git pull, then switch back to feature and then run "git rebase develop". – fumeng May 17 '22 at 14:42

1 Answers1

1

If you started working from another developer's branch (for example, you depended on changes that another developer is working on and they are still in the process of approval), you need to be extra careful to not move those revisions along with yours when you are rebasing... unless you know what you are doing.

Suppose that the other developer rebased their branch. Now you are standing on revisions that are not relevant to the work of the other feature branch.

How do you deal with this? You need to tell git what not to rebase. Say the last revision of the work of the other developer's branch is X in your branch:

git rebase --onto develop X my-branch

That should get rid of those revisions.

PS I read in the comments that you did not start from another developer's branch? Then I would ask: did anybody force-push into develop branch? (I am assuming your develop branch is in sync with the upstream develop branch, by the way).

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • Thank you for that explanation. Maybe I should have gone thru an interactive rebase just to ensure something like this didn't happen. I think what happened was that when I did a "git rebase develop" that my local ref for develop was out of sync with remote. maybe that was the problem. – fumeng May 17 '22 at 14:40