简体   繁体   中英

New to Git Version Control

I am new to git and i have ran into an issue. I created a feature branch from the master branch and did some commits, even pushed them.

After I realized I was supposed to create my feature branch from another branch which is created from the master. Any suggestions, if there is any workaround here or do I just need to create the new branch as I was supposed to and write all the code again.

Thanks.

One way to do it is with git rebase .

Standing in the branch where you made the changes, after creating the other branch where you should have made the commits

git rebase --interactive newbranch

Select the commits to pick and push.

Another, equivalent way to do it is manually reverting the commits, stashing the changes and applying them to the other branch.

Stash the changes, in your feature branch where you added the commits

git reset --soft HEAD~{NUMBER OF COMMITS}
git stash

Check out the other branch and pull the latest changes

git checkout otherbanch
git pull origin otherbanch

Create a new feature branch to apply the changes to

git checkout -b newbranch

Apply the stashed changes

git stash apply

Fix conflicts if necessary, commit and push.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM