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?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-06-23 09:12:17
0
7
1071

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.

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(7)
过去多啦不再A梦

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'

阿神
git branch -D uop-151
git checkout master
git checkout -b uop-151
学霸

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

阿神

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/...

習慣沉默

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

代言

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.

学习ing

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template