git - cherry-picked feature commits into new branch, reverted commits, rebase not working as expected

最后都变了- 提交于 2019-12-01 05:54:04

You can fix this by checking out your feature branch and doing:

git rebase --onto dev HEAD~<number of commits you care about> --force-rebase

This instructs git to replay the commit range that you specify and to ignore whether or not the commit occurred at a point in time prior to the commits on dev.

Note that this will leave you with a history that looks like:

<did some work> -- <reverted all of that work> -- <re-did that work>

which may not be all that useful to you. Some of the other answers here detail how you can get a cleaner history by rewriting it, depending on your team's tolerance for history rewriting.

Assuming that you don't mind rewriting history, a better way to do whole thing would have been an interactive rebase:

  • Create a branch foo just before the commit to be removed.
  • To avoid losing it, tag or make a branch at the commit to be removed.
  • Put yourself on the branch in question (e.g. git checkout your-dev-branch).
  • git rebase -i foo
  • You'll be put into an editor with "pick" lines for each commit between foo and the current head. Delete the line[s] for the commit[s] that you want to remove. Save, quit
  • Resolve any conflicts.

This will

  • Rewrite the dev branch with the relevant commits removed.
  • Leave the pulled feature on a branch (or tagged, depending on the second step), for later cherry-picking (or otherwise) onto your revised dev branch. I'd always take a clone or put a few judicious tags in there before doing this sort of thing, in case it all goes wrong.

Am not an expert, but how about reverting the feature and then creating the branch followed by the cherry pick of the feature sha1s on the new branch.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!