Reputation: 101
So, I'm new to git and its quite a learning curve - one that i'm navigating horribly as you will soon see.
I created a dev branch from master and then made a few commits.
dev -> A -> B -> C-> D
I then merged to master.
(on branch dev)$ git merge master
git checkout master
git merge dev
Then i squashed the 4 commits and pushed to remote
git rebase -i HEAD~4
git push
So now
master: ABCD
(I now realize this would've done what i wanted too.)
git reset --soft HEAD~3 &&
git commit
Here's where things go to hell.
I continued development on dev brach and made a commit.
dev -> A -> B -> C-> D -> E
Then, having realized the spot i got myself into, i created a new branch from master, new_dev but - i rebased dev onto it and made a couple of commits (Again, evidently a stupid thing to do)
new_dev -> ABCD -> A -> B-> C-> D-> E -> F-> G
Now, having realized the error of my ways I'm considering doing the following but would like approval from more experienced people.
Let me know if I've got it right this time or what i should do instead.
Upvotes: 0
Views: 107
Reputation: 9062
That's the reason why you usually want to squash on the feature/dev branch, not on master.
But since you are already in this situation, you can create a new branch from master and use git cherry-pick
to add the commits you want from dev (cherry-pick simply creates new commits on the current branch that do the same thing as the commit specified as argument). And you have to throw away the current dev branch.
Alternatively, you can merge dev into master, with a possible nasty merge conflict, and then either create a new dev branch or merge master into dev to sync them up.
I can't stress this enough. You don't want to do any changes on the master branch, including squashes, resets etc which might create inconsistencies with the dev branch. That's why you have a dev. In master, what's merged is merged for good.
Upvotes: 1