Black
Black

Reputation: 20212

Why are commits from other pull request in my new pull request?

I am fairly new to working in a team with git.

I startet at "origin/master".

enter image description here

  1. First I created a new branch feature/26062018-offline-seite_ef.

  2. I added commits.

  3. I checked out the local master branch.

  4. I merged in the feature branch (git merge feature/26062018-offline-seite_ef)

  5. I pushed to the remote server (git push origin feature/26062018-offline-seite_ef)

  6. I switched to Bitbucket and created the pull request. There is a commit with id f0ebe14 but I expected 0593ba83.

enter image description here

Then I developed something else:

  1. First I created a new branch feature/26062018-newsletter-popup_ef.

  2. I added commits.

  3. I checked out the local master branch.

  4. I merged in the feature branch (git merge feature/26062018-newsletter-popup_ef)

  5. I pushed to the remote server (git push origin feature/26062018-newsletter-popup_ef)

  6. I switched to Bitbucket to create the pull request. But this is what I get:

enter image description here

I expected only the commit 7a52ce3b but instead I get these two.

What is wrong with my git workflow?

Upvotes: 3

Views: 662

Answers (3)

Black
Black

Reputation: 20212

I "solved" it by executing git reset --hard 6d960676 (reset to origin/master). Then I started over again completly, but this time I did not merged with my local master at all after I developed my feature. I just let the branch open and unconnected to my local master and push.

And everytime before I create a new feature branch, I checkout master first so that the branch is not created at top of the other feature branch.

Problem: I have to checkout the specific branches everytime if I want to see the changes made from the feature, I can't combine the features. As soon as I merge, then the mess starts again...

Upvotes: 0

torek
torek

Reputation: 487745

Note what you did in your steps 3-5 initially:

  1. I checked out the local master branch.

  2. I merged in the feature branch (git merge feature/26062018-offline-seite_ef)

  3. I pushed to the remote server (git push origin feature/26062018-offline-seite_ef)

What you did in step 4 is sometimes called a test merge. You did not push this merge anywhere, but you still have it in your repository.

You then proceeded, in your second group of steps, to:

created a new branch feature/26062018-newsletter-popup_ef.

This particular name, at this point in time, named the test merge that you made. The additional commits you made in step 2 build from this merge, so the commits you pushed in the end were:

  • all the commits you made in the first group (they probably already had those via your earlier pull request so that part probably went very fast); plus
  • the merge commit; plus
  • the commits you made after creating feature/26062018-newsletter-popup_ef.

Hence, those are the commits in your second pull request: all of the ones in your first, plus the merge, plus the ones you wanted to have in it.

What you should have done was any of the following:

  • make the test merge on some other branch (not your master), or
  • make the test merge on master but then remove it (git reset --hard HEAD~1 for instance); or
  • don't even bother with the test merge (only good practice in some restricted cases).

What you need to do at this point is retract the second pull request. You can make a new branch starting from the last commit before the first test merge—remember, at this point you have two test merges on your master. This starting point will generally also match the commit hash ID of origin/master. Now that you have a new branch, you can use git cherry-pick to copy the desired commits to new commits that extend the graph correctly, test-merge the commits if you like, and push these commits. (You can re-use the branch name by renaming the branch that has too many commits, using git branch -m; see the documentation.)

Upvotes: 2

Chris Maes
Chris Maes

Reputation: 37712

You created the new branch feature/26062018-newsletter-popup_ef from the feature/26062018_offline-seite_ef branch instead of the master branch. You thus included the changes from the feature/26062018_offline-seite_ef branch into your branch.

Upvotes: 1

Related Questions