开发者

How to pass a time stamp to a Git tag

I'm interested in running this on my git master branch for timestamped releases:

tag -a date_time_as_tag_name -m "开发者_如何转开发new release"
git push tags

Is there a command that will create the timestamp for me?


Try this in your ~/.gitconfig file:

git config alias.datetag '!git tag `date "+%Y%m%d%H%M"`'


If you're on a unix setup, you can use date. On windows, there's the same named date command.


In addition to jschorr's answer, to create an annotated tag using the current Date/Time as the name:

git tag -a `date “+%d%b%Y%H%M%S”` -m "enter your comment here" 

Listing with git tag we can see something like:

23Nov2017115959


With Git 2.16 (Q1 2018), you will have a more intuitive way to pass a timestamp to a Gti command: for instance, "git config --expiry-date gc.reflogexpire" can read "2.weeks" from the configuration and report it as a timestamp, just like "--int" would read "1k" and report 1024, to help consumption by scripts.

See commit 5f96742 (18 Nov 2017) by Haaris Mehmood (``).
(Merged by Junio C Hamano -- gitster -- in commit 6cddb73, 06 Dec 2017)

config: add --expiry-date

Add --expiry-date as a data-type for config files when 'git config --get' is used. This will return any relative or fixed dates from config files as timestamps.

This is useful for scripts (e.g. gc.reflogexpire) that work with timestamps so that '2.weeks' can be converted to a format acceptable by those scripts/functions.

Following the convention of git_config_pathname(), move the helper function required for this feature from builtin/reflog.c to builtin/config.c where other similar functions exist (e.g. for --bool or --path), and match the order of parameters with other functions (i.e. output pointer as first parameter).

So the git config documentation now reads:

--expiry-date:

git config will ensure that the output is converted from a fixed or relative date-string to a timestamp.
This option has no effect when setting the value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜