git:签出一个标签,修改一些东西,然后再次标记它 [英] git: check out a tag, modify something, then tag it again

查看:31
本文介绍了git:签出一个标签,修改一些东西,然后再次标记它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得我应该知道这一点,但我很困惑.

I feel like I should know this, but I'm getting confused.

我在 github 上创建了一个仓库.我需要签出一个标签(称为'v1.0.5'),修改文件上的一条语句,用一个名为'1.0.5'的新标签(没有'v')重新标记该状态,然后执行对 master 的更改相同.

I forked a repository on github. What I need is to checkout a tag (called 'v1.0.5'), modify a statement on a file, re-tag that state with a new tag called '1.0.5' (without the 'v'), then do the same changes to master.

让我更清楚.我正在将 EightMedia 的 Hammer.js 从命名的 AMD 模块更改为匿名模块.

Let me be clearer. I'm changing EightMedia's Hammer.js from a named AMD module to an anonymous one.

我必须更改的唯一文件是 src/outro.js.文件不会改变从标签 v1.0.5 到 HEAD.

the only file I have to change is src/outro.js. The file doesn't change from tag v1.0.5 to HEAD.

我想改变

// requireJS module definition
if(typeof window.define === 'function' && window.define.amd) {
    window.define('hammer', [], function() {
        return Hammer;
    });
}

// requireJS module definition
if(typeof window.define === 'function' && window.define.amd) {
    window.define(function() {
        return Hammer;
    });
}

我想要的是:签出 v1.0.5,更改该文件,然后以我有一个包含 exact 的标签 1.0.5 的方式推送 repov1.0.5 的内容,加上更改.必须将标签推送到远程.

What I want is: checkout v1.0.5, change that file, and push the repo in a way that I have a tag 1.0.5 that comprises the exact content of v1.0.5, plus the changes. The tag must be pushed to remote.

然后,checkout master,再次修改文件,再次push到master.

Then, checkout master, change the file again and push it again to master.

结帐 v1.0.5 时我很迷茫,我进入了分离的 HEAD 状态.提交后,我在哪里推送修改?以及如何标记它们并将标签推送到远程?

I'm quite lost when checkout v1.0.5 and I get in the detached HEAD state. After committing, where do I push the modifications? And how can I tag them and push tags to remote?

推荐答案

首先,使用原标签结账:

First, checkout using the original tag:

git checkout v1.0.5

这将使您处于分离的 HEAD 状态 - 您的提交不会特别转到任何分支.这听起来像你想要的!

This will put you in detached HEAD state - your commits won't go to any branch in particular. This sounds like what you want!

现在,进行更改、暂存并提交.

Now, make your changes, stage them, and commit.

git commit -a -m "Commit message"

您仍处于分离的 HEAD 状态,但您处于新的提交状态 - 具有您想要的更改和历史记录的提交.所以标记它!

You're still in detached HEAD state, but you're at a new commit - the one that has both the changes and history you want. So tag it!

git tag 1.0.5

推回远程(假设你的仍然命名为 origin):

To push back to the remote (assuming yours is still named origin):

git push origin 1.0.5

这将推送标签本身 (1.0.5) 以及它指向的所有必要的提交历史记录.

This will push the tag itself (1.0.5) as well as all the necessary commit history it points to.

请注意,您的更改不会包含在除此标记之外的任何位置其他.根据您的问题,我认为这就是您想要的,但如果您确实需要合并回master,您可以遵循:

Note that your change won't be included anywhere other than this tag. Based on your question, I think that this is what you want, but if you do need to merge back to master, you can follow with:

git checkout master
git merge 1.0.5

这篇关于git:签出一个标签,修改一些东西,然后再次标记它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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