Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pushes old commit in different branch to new branch

I've been struggling with GIT for a while now since it does some weird things.

I have a base commit with the initial code.

Ok next I make a branch do my edits and commit and push:

git checkout -b feature/feature1
git commit -m "added feature1"
git push origin feature/feature1

Now I do a pull request on that feature.

After that I change branch and update for example:

git checkout -b chore/update-framework
git commit -m "updated framework"
git push origin chore/update-framework

At this point when I try a pull request on the 2nd push, it contains the first commit with all the feature stuff in it. So all the changed files from that commit are in the new pull request, while the old pull request only contains the feature files.

What am I doing wrong?

like image 819
totalvamp Avatar asked Dec 08 '22 22:12

totalvamp


1 Answers

When you did:

git checkout -b chore/update-framework

You did not checkout on master before.

To start a new branch from the commit you want (example with master):

git checkout -b chore/update-framework master

or:

git checkout master
git checkout -b chore/update-framework

or:

git branch chore/update-framework master
git checkout chore/update-framework

To correct your mistake, you can do:

git rebase --onto master feature/feature1 chore/update-framework

Git will pick all your commits of chore/update-framework which are not pointed by feature/feature1, then it will put them onto master and finally update your chore/update-framework branch.

like image 50
jbaptperez Avatar answered Dec 11 '22 09:12

jbaptperez