如何将 master 分支恢复为 git 中的标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6872223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I revert master branch to a tag in git?
提问by Manjunath Manoharan
We have branches origin and develop.
The initial state of master was tagged at tag_ABC
.
我们有分支机构的起源和发展。master 的初始状态标记为tag_ABC
。
We have few changes made to the develop branch and pushed to origin. Then we have accidentally merged develop into master and pushed to origin.
我们对开发分支进行了很少的更改并推送到原点。然后我们不小心将 develop 合并到 master 并推送到 origin。
Now we would like to revert master to the checkpoint tag_ABC
. How can we do that?
现在我们想将 master 恢复到 checkpoint tag_ABC
。我们怎么做?
回答by Pawe? Obrok
You can do
你可以做
git checkout master
git reset --hard tag_ABC
git push --force origin master
Please note that this will overwrite existing history in the upstream repo and may cause problems for other developers who have this repo checked out.
请注意,这将覆盖上游存储库中的现有历史记录,并可能会给签出此存储库的其他开发人员带来问题。
回答by John
This isn't a direct answer to the question but this page comes back when searching for ways to revert a branch's code to a tag release.
这不是问题的直接答案,但在搜索将分支代码恢复为标记发布的方法时,会返回此页面。
Another way is to create a diff between the current state of the branch and the tag you want to revert to and then apply that to the branch. This keeps the version history correct and shows the changes going in then coming back out again.
另一种方法是在分支的当前状态和要恢复到的标记之间创建差异,然后将其应用于分支。这使版本历史保持正确,并显示发生的更改然后再次返回。
Assuming your branch is called masterand the tag you want to go back to is called 1.1.1
假设你的分支叫做master而你想要返回的标签叫做1.1.1
git checkout 1.1.1
git diff master > ~/diff.patch
git checkout master
cat ~/diff.patch | git apply
git commit -am 'Rolled back to version 1.1.1'
git push origin master