search

Home  >  Q&A  >  body text

Git accidentally created a new branch based on other branches, but I want to create a new branch based on the main branch. How to deal with it?

I created a new branch uop-151, which is based on uop-387, but I want to build it based on the main branch, but now it has been developed and submitted, but I only want to submit uop-151's stuff, not uop- 387, how to deal with it?

I only want to submit the top commit, and I don’t want to submit the following commits. The main thing is that I have pushed to the remote branch.

曾经蜡笔没有小新曾经蜡笔没有小新2713 days ago1048

reply all(7)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-23 09:14:17

    It has nothing to do with whether it is pushed to the remote. Even if push is done, you can still push -f to modify it. .

    In this case, just use git rebase --onto. Documentation: https://git-scm.com/docs/git-...

    Your situation can be abstracted into: A - B - C - D - E - F - G. Where A is the original starting point (master), B C D E F is from uop-387, and you don’t want it. G is your own commit and should be kept.

    Execute git checkout uop-151 first to make sure you are on the branch you want to operate.

    Then git rebase --onto uop-151~6 uop-151~1 uop-151

    Result: A - G'

    reply
    0
  • 阿神

    阿神2017-06-23 09:14:17

    git branch -D uop-151
    git checkout master
    git checkout -b uop-151

    reply
    0
  • 欧阳克

    欧阳克2017-06-23 09:14:17

    Git has a cherry-pick command, I don’t know if it meets your needs. Please download the usage from Baidu

    reply
    0
  • 阿神

    阿神2017-06-23 09:14:17

    If you only performed the operation locally and have not pushed it to the upstream server, you can use git rebase to rebase uop-151 to master.

    Official Git Rebase documentation (need to circumvent the wall)
    https://git-scm.com/docs/git-...

    Other reference documents
    http://blog.csdn.net/hudashi/...

    reply
    0
  • 習慣沉默

    習慣沉默2017-06-23 09:14:17

    Cherry-pic the commit id of your development submission to master.

    reply
    0
  • 代言

    代言2017-06-23 09:14:17

    If you haven’t pushed yet, you can perform the git reset xxxx operation on the uop-387 branch. Where xxxx is the latest hash of the uop-151 branch.

    Then switch to the master branch and build a branch based on master again. Don’t forget to use the --merge parameter.


    If you are familiar with git, you can use the cherry-pic command.

    reply
    0
  • 学习ing

    学习ing2017-06-23 09:14:17

    After checking out the main branch, just create a new branch.

    reply
    0
  • Cancelreply