【问题标题】:git commit amendment without losing the tags [duplicate]git commit 修改而不丢失标签[重复]
【发布时间】:2018-05-30 07:00:06
【问题描述】:

我有以下在 Git 的提交后挂钩上运行的脚本:

#!/bin/sh
# by Martin Seeler, and
# by Jorge Javier Araya Navarro

# destination of the final changelog file
OUTPUT_FILE=CHANGELOG.md

# generate the changelog
if ! type gitchangelog > /dev/null; then
    echo "ERROR: Please install gitchangelog"
    exit 1
fi

gitchangelog > $OUTPUT_FILE

# prevent recursion!
# since a 'commit --amend' will trigger the post-commit script again
# we have to check if the changelog file has changed or not
res=$(git status --porcelain | grep $OUTPUT_FILE | wc -l)
if [ "$res" -gt 0 ]; then
  git add $OUTPUT_FILE
  git commit --amend --no-edit
  echo "Populated Changelog in $OUTPUT_FILE"
fi

这很方便使用 gitchangelog 生成 CHANGELOG 文件,而无需创建新的提交来注册该文件上的更改。

但是,如果我在 HEAD 上有一个标签,在运行 commit --amend 之后,标签是 “丢失”,因此我必须在本地和远程删除它并重新创建它,这很烦人。

我正在尝试想办法让脚本在修改后移动标签,但此时我不确定我在做什么。我应该首先列出 HEAD 上的标签吗?修改后可以移动标签吗? Git 会明白我的意思吗?

【问题讨论】:

    标签: git git-tag git-amend


    【解决方案1】:

    您可以查看git tagm alias I described here,以便在git commit --amend 之后移动您的标签。

    这将使以下序列自动化:

    • 找到标签,
    • 移动(即重新创建)
    • 删除旧的。

    【讨论】:

    • 知道如何获取 HEAD 上的标签列表以供以后与别名一起使用吗?
    • @shackra 你可以在修改之前列出这些标签stackoverflow.com/a/15353441/6309:git tag --points-at HEAD
    猜你喜欢
    • 2014-02-26
    • 2013-04-01
    • 1970-01-01
    • 2022-11-02
    • 2021-05-08
    • 2015-04-21
    • 2012-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多