1162

gitは初めてなので、リポジトリの先頭にタグを設定したいと思います。私たちの本番コードは最初のリポジトリと同じですが、それ以来コミットを行っています。最初のタグを使用すると、本番環境を既知の安定した状態に「ロールバック」できます。

では、任意の古いコミットにタグを追加するにはどうすればよいでしょうか。

4

8 に答える 8

1776

例:

git tag -a v1.2 9fceb02 -m "Message here"

9fceb02コミットIDの最初の部分はどこにありますか。

次に、を使用してタグをプッシュできますgit push origin v1.2

git log現在のブランチのすべてのコミットIDを表示するために行うことができます。

Pro Gitの本には、タグ付けに関する優れた章もあります。

警告:これにより、現在の日付でタグが作成されます(たとえば、その値はGitHubリリースページに表示される値です)。タグにコミット日を付けたい場合は、別の回答を参照してください。

于 2010-12-09T23:27:28.277 に答える
189

Just the Code

# Set the HEAD to the old commit that we want to tag
git checkout 9fceb02

# temporarily set the date to the date of the HEAD commit, and add the tag
GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" \
git tag -a v1.2 -m"v1.2"

# set HEAD back to whatever you want it to be
git checkout master

Details

The answer by @dkinzer creates tags whose date is the current date (when you ran the git tag command), not the date of the commit. The Git help for tag has a section "On Backdating Tags" which says:

If you have imported some changes from another VCS and would like to add tags for major releases of your work, it is useful to be able to specify the date to embed inside of the tag object; such data in the tag object affects, for example, the ordering of tags in the gitweb interface.

To set the date used in future tag objects, set the environment variable GIT_COMMITTER_DATE (see the later discussion of possible values; the most common form is "YYYY-MM-DD HH:MM").

For example:

$ GIT_COMMITTER_DATE="2006-10-02 10:31" git tag -s v1.0.1

The page "How to Tag in Git" shows us that we can extract the time of the HEAD commit via:

git show --format=%aD  | head -1
#=> Wed, 12 Feb 2014 12:36:47 -0700

We could extract the date of a specific commit via:

GIT_COMMITTER_DATE="$(git show 9fceb02 --format=%aD | head -1)" \
git tag -a v1.2 9fceb02 -m "v1.2"

However, instead of repeating the commit twice, it seems easier to just change the HEAD to that commit and use it implicitly in both commands:

git checkout 9fceb02 

GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" git tag -a v1.2 -m "v1.2"
于 2014-02-13T16:09:24.397 に答える
160

これを行う最も簡単な方法は次のとおりです。

git tag v1.0.0 f4ba1fc
git push origin --tags

タグ付けf4ba1fcするコミットのハッシュの先頭であり、タグ付けv1.0.0するバージョンです。

于 2014-06-02T14:30:34.790 に答える
42

コマンドを使用:

git tag v1.0 ec32d32

v1.0 はタグ名で、ec32d32 はタグ付けするコミットです

完了したら、次の方法でタグをプッシュできます。

git push origin --tags

参照:

Git (リビジョン管理): GitHub の特定の以前のコミット ポイントにタグを付けるにはどうすればよいですか?

于 2016-09-21T20:29:08.563 に答える