How can I make my develop branch ahead of master branch?
What happened was:
- There is no git repo
- I found some old code, i.e. version 1.0
- I started working on it and changed some behavior, i.e. version 1.1
- I decided that I should create a git repo before things get messy, and I did
- I pushed version 1.1 to the repo as origin/master as the initial commit
- But what I really wanted was to create a tag for version 1.0,
- So I also created origin/develop with version 1.1
- Then I checked out origin/master, deleted my changes, commited and tagged it version 1.0 again.
- I git push the tag and changes to master
- Now my master is ahead of develop
- But actually I want develop to be ahead of master
I tried to git pull and rebase, but both changed my develop version 1.1 into master version 1.0.
What should I do?
CodePudding user response:
A git log --decorate --graph --oneline --all --branches
in your local repository should show you something like:
x commit for 1.0 (HEAD, master, origin/master)
|
x commit for 1.1 (develop, origin/develop)
You can therefore reset your develop
branch to master
, and cherry-pick your old develop
commit, on top of master
.
git switch -C develop master
git cherry-pick origin/develop
git push -f -u origin develop
(assuming here there was only only commit on develop
)
The new log should show develop
ahead of master
now:
x commit for 1.1 (HEAD, develop, origin/develop)
|
x commit for 1.0 (master, origin/master)