如何将Git提交移动到另一个分支并在原始分支中将其删除

如何将Git提交移动到另一个分支并在原始分支中将其删除

本文介绍了如何将Git提交移动到另一个分支并在原始分支中将其删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在在分支中有以下提交:

I have the following commits in a branch now:

我错误地开始了分支B的工作,并在分支A中提交了 b58 151 5ef .

I mistakenly started Branch B work and have committed b58, 151 and 5ef in Branch A.

这3个提交应该在分支B中,而不是在分支A中.所有3个提交都已推送到我的远程Git服务器.

Those 3 commits supposed to be in the Branch B and not in the Branch A. All 3 commits have been pushed to my remote Git server.

我的问题

如何将这3个提交移至分支B并在分支A中将其删除?对于分支B,我希望它从分支A中的commit 97b 分支出来.

How do I move those 3 commits to Branch B and delete them in Branch A? For the Branch B, I want it to branch off from commit 97b in the Branch A.

推荐答案

我现在将创建分支B,然后将分支A重置为您想要的状态,然后需要强制将其推到远程服务器.

I would create the branch B now and then reset branch A to the state you want it to be, and then you will need to force push it to the remote server.

git checkout -b branchB
git checkout branchA
git reset --hard HEAD~3
git push -f

一路检查git log和git status的状态.

Check the status with git log and git status all the way along.

这篇关于如何将Git提交移动到另一个分支并在原始分支中将其删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:54