我如何将我最近的承诺转移到一个新的分支机构,并在这些承诺完成之前重新定义主? 例如:

master A - B - C - D - E

为此:

newbranch     C - D - E
             /
master A - B 

当前回答

这里的大多数解决方案计算了你想回去的承诺数量,我认为这是一个错误的方法,计算需要计算。

你可以简单地通过你想要的承诺的承诺,或者换句话说,你想要的承诺是最后的承诺:

(重定向自Commit Hash)

为了避免这一点:

1) git checkout master

2) git branch <feature branch> master

3) git reset --hard <commit hash>

4) git push -f origin master

其他回答

我很惊讶,没有人这样推荐:

git checkout master
git checkout <commit hash from which you want to split>
git checkout -b new_branch
git rebase master
git checkout master
git reset --hard <commit hash you splitted>

要解释:

步骤我们检查的承诺,我们想要分裂,然后从这个承诺创建一个新的分支,做 rebase 将同步 new_branch 和 master. 因此,现在我们有两个相同的分支与同样的承诺重新设置在 master,我们清理后分裂列表项目后最后的承诺

我不得不将7个承诺从一个旧行业转移到一个新行业。

git checkout old-branch     # in the example, master
git reset --hard h4sh       # h4sh is the hash for the commit 
git checkout -b new-branch  
git push origin new-branch

在 git checkout new-branch 之后,我得到了好 git log 和 git 状态,但是,当我访问旧行(git checkout old-branch)时,我得到了“git 落后于 7 行,可以快速推进”。

git checkout old-branch
git status 
> git is behind by 7 commits and can be fast-forwarded
git push origin old-branch -f

在这一步之后,最后7个承诺仅适用于新分支,而以前的承诺则适用于Bitbucket树的旧分支和新分支。

我怎么能离开这

A - B - C - D - E 
                |
                master

到此?

A - B - C - D - E 
    |           |
    master      newbranch

兩個命令

吉特分支 -m 主新分支

给予

A - B - C - D - E 
                |
                newbranch

吉特分支大师B

给予

A - B - C - D - E
    |           |
    master      newbranch

要做到这一点,而不重写历史(即如果您已经推出了承诺):

git checkout master
git revert <commitID(s)>
git checkout -b new-branch
git cherry-pick <commitID(s)>

那么,两支分支都可以在没有武力的情况下被推动!

TLDR

git checkout branch_to_remove_commits
git reset --hard ${hash_of_new_tip}
git checkout -b branch_to_store_commits
# Move commits (single hash, list of hashes or range ffaa..ffoo) 
git cherry-pick ${commit_hash}
git push --set-upstream origin branch_to_store_commits
# Switch back to last branch
git checkout -
git push -f

為我

git log --pretty=oneline -n ${NUMBER}

最好的工作是识别所涉及的承诺哈希。