我在一个我不该做的树枝上做了一些承诺!
Sprint 1分公司
我想将提交#2 - #4移动到热修复分支中,以便它们可以在稍后的某个日期合并回Sprint 1分支。重要的是,无论我在Sprint 1分支上做什么来暂时摆脱这些提交,当我将它们合并回其中时,它不会优先于这些提交(例如,在为它们创建一个修复分支之后恢复它们)。我该怎么做?
发布于 2019-08-07 09:48:22
与以往一样,在git中,有许多实现某些目标的可能性。因此,假设您在分支sprint上有4次提交,并且希望将最后一次提交移动到分支修复。为了模拟您的问题,我创建了sprint分支如下:
git checkout -b sprint
touch c1 c2 c3 c4
git add c1
git commit -m "commit 1"
git add c2
git commit -m "commit 2"
git add c3
git commit -m "commit 3"
git add c4
git commit -m "commit 4"
git push origin sprint现在,我们只从fix分支的head创建sprint分支,而不是移动提交:
git checkout -b fix
git push origin fix现在,我们将sprint分支重置为第一次提交。
git checkout sprint
git log --oneline # copy the hash of the first commit, say f58f8d8
git reset --hard f58f8d8
git push -f origin sprint # -f (force option) is needed because of the hard reset因此,fix分支现在拥有所有的提交,而sprint分支只有第一个提交,我理解,这正是您所需要的。
编辑:您需要RW+权限才能使用-f或--force选项(请参阅下面的注释)。
发布于 2019-08-07 09:20:00
在这种情况下使用git重碱。它将提交重定向到另一个分支。
https://stackoverflow.com/questions/57390557
复制相似问题