我如何将我最近的承诺转移到一个新的分支机构,并在这些承诺完成之前重新定义主? 例如:
master A - B - C - D - E
为此:
newbranch C - D - E
/
master A - B
我如何将我最近的承诺转移到一个新的分支机构,并在这些承诺完成之前重新定义主? 例如:
master A - B - C - D - E
为此:
newbranch C - D - E
/
master A - B
当前回答
在一般...
由 sykora 曝光的方法是最好的选择,但有时不是最简单的方法,而且不是一般的方法。
为了实现OP想要的,它的2步过程:
步骤1 - 注意你想要的新行业的主人的承诺
执行
git checkout master
git log
在这里我将使用: C 承诺: 9aa1233 D 承诺: 453ac3d E 承诺: 612ecb3
注意:您可以使用前七个字符或整个承诺字符。
步骤2 - 把它们放在新行业
git checkout newbranch
git cherry-pick 612ecb3
git cherry-pick 453ac3d
git cherry-pick 9aa1233
或(在 Git 1.7.2 + 上,使用范围)
git checkout newbranch
git cherry-pick 612ecb3~1..9aa1233
git cherry-pick 适用于新行业的这三个承诺。
其他回答
如果你想将你的承诺转移到一个现有分支,它会看起来如下:
git checkout existingbranch
git merge branchToMoveCommitFrom
git checkout branchToMoveCommitFrom
git reset --hard HEAD~3 # Go back 3 commits. You *will* lose uncommitted work.
git checkout existingbranch
警告: 这个方法工作,因为你正在创建一个新的分支与第一个命令: git 分支新分支. 如果你想将承诺转移到一个现有分支,你需要将你的变化融入现有分支之前执行 git 重新设置 --hard HEAD~3 (见移动到一个现有分支上)。
除非有其他情况涉及,否则可以轻松地通过连接和旋转。
# Note: Any changes not committed will be lost.
git branch newbranch # Create a new branch, saving the desired commits
git checkout master # checkout master, this is the place you want to go back
git reset --hard HEAD~3 # Move master back by 3 commits (Make sure you know how many commits you need to go back)
git checkout newbranch # Go to the new branch that still has the desired commits
git reset --hard a1b2c3d4
最后,您可能需要强迫将最新的更改推到主重复:
git push origin master --force
警告: 使用 Git 版本 2.0 及以后,如果您稍后 git 将新分支转移到原始(主)分支上,您可能需要在转移期间明确的 --no-fork-point 选项,以避免失去所承担的承诺。
要做到这一点,而不重写历史(即如果您已经推出了承诺):
git checkout master
git revert <commitID(s)>
git checkout -b new-branch
git cherry-pick <commitID(s)>
那么,两支分支都可以在没有武力的情况下被推动!
最简单的方式就是这样做:
任命主分支到您的新分支(假设您在主分支):
git branch -m newbranch
2、从你想要的承诺中创建主分支:
git checkout -b master <seven_char_commit_id>
例如 git checkout -b master a34bc22
注意:新行业的上流将是起源/主流。
從其他文章中採取一些想法,避免任何與重新安裝有關的事情,並且非常偏見,我的解決方案是:
git 分支 # 更改可在新分支 git 推 # 上传,您可能需要与“--set-upstream”混淆,例如 git 推 --set-upstream https:/// 检查新分支在 git 通过 GUI 破坏现行目录从 git 存储库重新克隆
我不自豪,但我保留了我的数据。
我不得不将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树的旧分支和新分支。