让我们说我们有一个hotfixes
分支是由...创建的master
.我们添加了提交hotfixes
,但这些提交没有用,所以现在我们想从一个新的副本开始master
.
为了更好地澄清,这是参考工作流程:http://nvie.com/posts/a-successful-git-branching-model/
让我们也说我们推hotfixes
到了origin
遥控器,因为我们设置得很糟糕,这是测试某些东西的唯一方法,所以我们还需要在远程服务器上重置分支.
如何重置hotfixes
为副本master
?
dan*_*nza 68
这就是我用基本的Git命令做到的:
git checkout hotfixes
git reset --hard master
git push --force origin hotfixes
Run Code Online (Sandbox Code Playgroud)
当然,通知每个工作人员都很重要hotfixes
.他们很可能不得不删除他们的本地副本并从一个新的副本开始.一个替代的,侵入性较小的想法是创建一个新的分支:
git checkout master
git branch -tb hotfixes-2 # this creates branch `hotfixes-2` from a copy of `master`
git push origin HEAD # this creates `hotfixes-2` on the remote server
Run Code Online (Sandbox Code Playgroud)
Mic*_*ild 39
你的意思是你想把你的本地推master
到远程hotfixes
分支?像这样:
git push origin +master:hotfixes
Run Code Online (Sandbox Code Playgroud)
但是,这要求您可以在远程端重写历史记录.
如果我正确地理解了你的问题,你正在寻找的是一种将分支指针移动origin/hotfixes
到指向当前版本的方法origin/master
.
如果是这种情况,这些命令集应该有效(假设您已经hotfixes
在过去的任何时间在本地git仓库中检出过):
# git branch -f does not allow modifying the currently checked out
# branch, so checkout any other branch than hotfixes
git checkout <SOME_OTHER_BRANCH_THAN_HOTFIXES>
# Move the branch pointer of hotfixes to the commit currently
# pointed by origin/master
git branch -f hotfixes origin/master
# Force push the history rewrite in the hotfixes branch
# into origin
git push -f origin hotfixes
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
49287 次 |
最近记录: |