jomni
jomni

Reputation: 789

Move previous commits to another branch

History looks like follows:

master branch     1-2-3-4
                         \
feature branch            5-6-7

I realized changes 2, 3 and 4 should have also gone into my feature branch and would like to move them as shown below.

master branch     1
                   \
feature branch      2-3-4-5-6-7

How should I go about? Nobody else is using my repo, I haven't pushed the commits since creating the branch and all changes are committed.

Upvotes: 2

Views: 54

Answers (1)

Jonathan Hall
Jonathan Hall

Reputation: 79526

Just delete the offending commits from master. They'll still be in your feature branch:

git checkout master
git reset --hard 1          # Replace '1' with the actual SHA for the commit 
git push -f origin master   # Sync to remote, if applicable

Upvotes: 4

Related Questions