2016-11-09 108 views
1

好吧,所以我遇到了问题或者可能不是,我只是不明白。上一次提交Git标签

我正在做的是试图提交并推送提交,但也标记它。

我从一饮而尽运行shell命令这样做,虽然这样有可能有一些做它,

git add [files]

git commit -m [message]

git tag -a [tag name] [branch] -m [message]

然后

git push origin [tag name]

但问题是该标签被推送在前一个提交,而不是我目前提交。

我现在的大口的任务是这样的:

var gulp = require('gulp'), 
plugin = require('gulp-load-plugins')({ 
    camelize: true 
}), 
ghPages = require('gulp-gh-pages'), 
run = require('gulp-run'), 
prompt = require('gulp-prompt'); 

module.exports = function() { 
console.log('Deployment is running currently, please be patient.'); 

return gulp.src('modules/**/*') 
    .pipe(ghPages({ 
    remoteUrl: '[user]@[ip]:[branch]', 
    branch: '[branch]' 
    })) 
    .on('end', function() { 
    return gulp.src('modules/**/*') 
    .pipe(prompt.prompt({ 
     type: 'input', 
     name: 'release', 
     message: 'Is this a new release? (y/n)', 
    }, function(res) { 
     if (res.release == 'y') { 
     return gulp.src('modules/**/*', { 
      read: false 
      }) 
      .pipe(prompt.prompt({ 
      type: 'input', 
      name: 'releaseNumber', 
      message: 'What is the new release version number? (e.g. x.x.x)' 
      }, function(res) { 
      run('git fetch --all').exec(); 
      run('git tag -a v' + res.releaseNumber + ' [branch] -m "Bump release"').exec(); 
      run('git push origin v' + res.releaseNumber + ' [branch]').exec(); 
      })); 
     } 
    })); 
}); 
}; 

什么是在控制台输出为:

Deployment is running currently, please be patient. 
[16:12:28] [gh-pages (branch)] Cloning repo 
[16:12:28] [gh-pages (branch)] Checkout remote branch `branch` 
[16:12:28] [gh-pages (branch)] Updating repository 
[16:12:29] [gh-pages (branch)] Copying files to repository 
[16:12:29] [gh-pages (branch)] Adding 1 files. 
[16:12:29] [gh-pages (branch)] Committing "Update 2016-11-09T21:12:18.579Z" 
[16:12:29] [gh-pages (branch)] Pushing to remote. 
[16:12:30] Finished 'deploy' after 12 s 
[16:12:30] Finished 'build' after 15 s 
? Is this a new release? (y/n) y 
? What is the new release version number? (e.g. x.x.x) 0.0.5 
$ git tag -a v0.0.5 branch -m "Bump release" 
$ git push origin v0.0.5 
To [user]@[ip]:[repo] 
    * [new tag]   v0.0.5 -> v0.0.5 

Commit log

正如你可以从图片看,标签ISN不会被放在我目前正在提交的最新的承诺上。它将它添加到以前的提交中。

我也在master推到另一个[分支]。也许这可能是问题?

+0

'git tag'不会创建提交。 – jthill

+0

没错。它创建标签。提交已经被创建并且被推送到这一行'[16:12:29] [gh-pages(branch)]添加1个文件。 [16:12:29] [gh-pages(branch)]提交“更新2016-11-09T21:12:18.579Z”[16:12:29] [gh-pages(branch)]推向远程。' –

+0

所以你在推动'词汇模块'?这不是创建一个快进合并提交,因此新的哈希?尝试使用git命令复制它,而不使用您的gulp文件。 – jkulak

回答

2

你应该展示一个问题的工作示例。这里是一个演示在这一切按预期工作:

#!/bin/bash 

init() { 
    git init --bare demo.git 
    git clone --quiet demo.git demo 
} 

commit_line() { 
    echo $1 > file 
    git add file 
    git commit -m "$2" 
} 

init 
pushd demo 
commit_line one first 
commit_line two second 
git tag -a -m "tag msg" tag-name HEAD 
git push origin master tag-name 

运行该脚本来创建一个demo.git纯仓库和demo工作文件夹。运行此之后,我运行以下命令:

[email protected] ~/tmp/demo.git $ git log --graph --decorate --abbrev-commit --oneline 
* 06a067a (HEAD -> master, tag: tag-name) second 
* daa72b4 first 

所以标签已被正确地使用最新的相关承诺这也是master尖端和currenly也HEAD。在工作文件夹中,除了我们还看到本地主服务器与上游存储库相匹配外,它看起来相似。

[email protected] ~/tmp/demo $ git graph 
* 06a067a (HEAD -> master, tag: tag-name, origin/master) second 
* daa72b4 first 
+0

更新了原始问题。抱歉没有包括所有东西。 –

2

我从你gulpfile跟着命令,运行下面的命令我的机器

$ git clone https://github.com/jkulak/git-test 
$ cd git-test/ 
$ touch first-file 
$ git add first-file 
$ git commit -m "Create first commit" 
$ touch second-file 
$ git add second-file 
$ git commit -m "Create second commit" 
$ git tag -a tag1 master -m "Creating first tag after second commit" 
$ git push origin master 
$ git push origin tag1 

。当我看在GitHub上,我看到:

  1. https://github.com/jkulak/git-test/commits/master - 与哈希第二次提交7008d2d
  2. https://github.com/jkulak/git-test/releases - tag1指向7008d2d

两者都指向/具有相同的散列/提交。

所以你写的“标签被推送到先前的提交,而不是我目前提交的内容。”似乎不是事实 - 请仔细检查一下,请吗?

我也不明白你最后一句话 - 你介意澄清一下吗?

也在推后,只是要确定

$ git log 
* 7008d2d (HEAD -> master, tag: tag1, origin/master) Create second commit 
* b6d13c4 Creted first commit 

它看起来不错在本地以及。

+0

更新了带插图的问题,并删除了最后一句,因为它让人迷惑。抱歉 –