问题描述
在我正在从事的这个项目中,我应该使用拉取请求将进度提交到一个回购中,并且每次提交都必须位于不同的分支中。问题是最后3次提交是在单个pull请求中进行的,我应该将它们分别移到单独的分支中。我尝试还原并创建新分支,但搞砸了,回到了正方形1。
In this project I'm working on, I'm supposed to commit my progress to a repo using pull requests, and every commit has to be in a different branch. The problem is that the last 3 commits were pushed in a single pull requests and I'm supposed to move them into separate branches each. I tried reverting and creating new branches but it got messed up and I'm back at square 1.
推荐答案
在此答案中,我将假设您的分支称为功能
,并且功能
具有三个相关的提交,这是它的三个最新提交
In this answer, I will assume that your branch is called feature
, and that feature
has the three commits in question as its three most recent commits.
从功能
创建新分支:
git checkout -b onecommit
最近两次核对提交,剩下三个提交中的第一个:
Nuke the two most recent commits, leaving the first of three commits remaining:
git reset --hard HEAD~2
现在将这个分支仅包含对您的回购的第一次提交:
Now push this branch containing just the first commit to your repo:
git push origin onecommit
要获得只有两个提交的分支,您会遵循类似的过程:
To obtain a branch with just two commits you would follow a similar process:
git checkout -b twocommits
git reset --hard HEAD~1
git push origin twocommits
这篇关于每次提交将分支拆分为一个分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!