2016-11-09 107 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

更新了帶插圖的問題,並刪除了最後一句,因爲它讓人迷惑。抱歉 –