Reputation: 20212
I am fairly new to working in a team with git.
I startet at "origin/master".
First I created a new branch feature/26062018-offline-seite_ef
.
I added commits.
I checked out the local master
branch.
I merged in the feature branch (git merge feature/26062018-offline-seite_ef
)
I pushed to the remote server (git push origin feature/26062018-offline-seite_ef
)
I switched to Bitbucket and created the pull request. There is a commit with id f0ebe14
but I expected 0593ba83
.
Then I developed something else:
First I created a new branch feature/26062018-newsletter-popup_ef
.
I added commits.
I checked out the local master
branch.
I merged in the feature branch (git merge feature/26062018-newsletter-popup_ef
)
I pushed to the remote server (git push origin feature/26062018-newsletter-popup_ef
)
I switched to Bitbucket to create the pull request. But this is what I get:
I expected only the commit 7a52ce3b but instead I get these two.
What is wrong with my git workflow?
Upvotes: 3
Views: 662
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
Reputation: 487745
Note what you did in your steps 3-5 initially:
I checked out the local
master
branch.I merged in the feature branch (
git merge feature/26062018-offline-seite_ef
)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:
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:
master
), ormaster
but then remove it (git reset --hard HEAD~1
for instance); orWhat 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
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