git:如何在不丢失历史记录的情况下将旧的标记版本转换为 master 版本? [英] git: how get an old tagged version into master, without losing history?

查看:30
本文介绍了git:如何在不丢失历史记录的情况下将旧的标记版本转换为 master 版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常小的项目,只有一个主分支.

This is a very small project with only a master branch.

我(轻量级)标记了生产中的源版本并将标记推送到源

I (lightweight) tagged a version of the source which was in production and pushed tag to origin

然后我向 master 提交了一些更改(这会在我们的开发系统上触发构建,以便我们可以对其进行测试)并将这些更改推送到原点.

Then I committed some changes to the master (which triggers a build onto our dev system so we can test it) and pushed these to origin.

现在我希望 master 包含标记版本,例如revert/reset",但我不想丢失我所做的可能在某些时候有用的更改.

Now I want master to contain the tagged version, something like "revert/reset", but I don't want to lose the changes I have made which may be useful at some point.

这个答案:怎么做我将 master 分支恢复为 git 中的标签?

就是要做到以下几点:

git checkout master
git reset --hard tag_ABC
git push --force origin master

我不知道这是做什么的,但它看起来很危险/剧烈,我正在寻找一个更简单(不太可能出错)的解决方案.

I have no idea what this does, but it looks dangerous/drastic, and I am looking for a simpler (less likely to go wrong) solution.

大概我需要检查主分支,然后合并标签,或者检查标记版本,然后合并到主分支?

Presumably I need to something like checkout the master branch, and merge in the tag, or checkout the tagged version, and merge in master?

例如

$ git checkout master
$ git pull
$ git merge mytag
$ git push

或者这是否会因为我要撤销的更改更新而感到困惑?

Or would this get confused because the changes I want to backout are newer?

我看到你可以设置主分支的位置标签"提交.所以我猜我只需要做

I have seen you can set the master branch "position tag" to a commit. So I am guessing I just need to do

git reset XXX

其中 XXX 是来自标签的提交的提交编号.如果此方法有效,我如何获取标签的提交编号(git hist 或 git history 在 mac 上不起作用)?既然这么简单,为什么还要用力和硬的东西?

Where XXX is the commit number of the commit from the tag. If this method works, how do I get the commit number of a tag (git hist or git history does not work on the mac)? If this is so easy, why the force and hard stuff?

如果我签出我的标签并执行 git status,它会显示HEAD detached at mytag"

If I checkout my tag, and do git status, it says "HEAD detached at mytag"

如果我不遵循食谱食谱,通常会以灾难告终,所以希望以前有人这样做过.

If I don't follow a cook book recipe, it usually ends in disaster, so hoping someone has done this before.

更新

我收到了几个回复,这很好,但不幸的是没有一个完整的食谱.由于缺乏更好的解决方案,我这样做了:

I got several replies, which was great, but none have a complete recipe unfortunately. For lack of better solution, I did this:

  1. 查看旧的标记版本.
  2. 将我更改的文件内容剪切并粘贴到 onenote 中.
  3. 检查头部.
  4. 在编辑器中打开修改后的文件,并粘贴 onenote 中的内容.
  5. 将更改提交给 master.

我相信有更好的方法.

推荐答案

一个简短的答案,应该可以:

A short answer, which should do the job:

git checkout -b my_tagged_branch tagname

checkout -b 创建一个新分支并将其签出.从文档这里

checkout -b creates a new branch and checks it out. From the docs here

$ git checkout v2.0  # or $ git checkout master^^

   HEAD (refers to commit 'b')
    |
    v a---b---c---d  branch 'master' (refers to commit 'd')
    ^
    |   tag 'v2.0' (refers to commit 'b')

Notice that regardless of which checkout command we use, HEAD now refers directly to commit b. This is known as being in detached HEAD state. It means simply that HEAD refers to a specific commit, as opposed to referring to a named branch.

然后您可以处理 my_tagged_branch,提交.如有必要,您再次结帐 master,然后 git merge my_tagged_branch.
如果您使用遥控器,请不要忘记推送,如果您想稍后看到该工作流程,请使用 git merge --no-ff my_tagged_branch (结果当然是一样的,只需检查使用 git log --graph --oneline.

You can then work on my_tagged_branch, commit. If necessary, you checkout master again and then git merge my_tagged_branch.
If you work with a remote, don't forget to push, if you like to see that workflow later on use git merge --no-ff my_tagged_branch (the result is of course the same, just check with git log --graph --oneline.

有关详细信息,请参阅@toreks 答案.

For details see @toreks answer.

这篇关于git:如何在不丢失历史记录的情况下将旧的标记版本转换为 master 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆