git_describe

本文介绍了如何使用git-describe命令在Git仓库中获取最近的tag,并展示了如何在ESP8266项目中显示版本信息。当源码有修改时,-dirty标志会添加到版本号后。还提供了不同选项的使用示例,如获取commit距离tag的数量和简化commitID。
摘要由CSDN通过智能技术生成

介绍

在很多git仓库中,发布版本中会在源码里面嵌入版本信息。比如 IDF 发布版本 v2.1,那如何将 v2.1 显示在源码中呢?

例如: esp-idf 下,esp-idf/make/project.mk 中嵌入了一下代码。

IDF_VER := $(shell cd ${IDF_PATH} && git describe --always --tags --dirty)

该命令会获取当前仓库当前的 commit 对应的最近的 tag。

git-describe - Describe a commit using the most recent tag reachable from it

–always

Show uniquely abbreviated commit object as fallback.

–tags

匹配远程的 refs/tag
Instead of using only the annotated tags, use any tag found in refs/tags namespace. This option enables matching a lightweight (non-annotated) tag.

–dirty

–dirty 意味着如果源码如果被修改了(git status),则会在版本后面加上 -dirty (默认),如版本为 v2.1 , 如果你修改了源码,则git

try: import thop except ImportError: thop = None logger = logging.getLogger(__name__) @contextmanager def torch_distributed_zero_first(local_rank: int): if local_rank not in [-1, 0]: torch.distributed.barrier() yield if local_rank == 0: torch.distributed.barrier() def init_torch_seeds(seed=0): torch.manual_seed(seed) if seed == 0: cudnn.benchmark, cudnn.deterministic = False, True else: cudnn.benchmark, cudnn.deterministic = True, False def select_device(device='', batch_size=None): s = f'YOLOv5 🚀 {git_describe() or date_modified()} torch {torch.__version__} ' cpu = device.lower() == 'cpu' if cpu: os.environ['CUDA_VISIBLE_DEVICES'] = '-1' elif device: # non-cpu device requested os.environ['CUDA_VISIBLE_DEVICES'] = device assert torch.cuda.is_available(), f'CUDA unavailable, invalid device {device} requested' cuda = not cpu and torch.cuda.is_available() if cuda: n = torch.cuda.device_count() if n > 1 and batch_size: # check that batch_size is compatible with device_count assert batch_size % n == 0, f'batch-size {batch_size} not multiple of GPU count {n}' space = ' ' * len(s) for i, d in enumerate(device.split(',') if device else range(n)): p = torch.cuda.get_device_properties(i) s += f"{'' if i == 0 else space}CUDA:{d} ({p.name}, {p.total_memory / 1024 ** 2}MB)\n" s += 'CPU\n' logger.info(s.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else s) # emoji-safe return torch.device('cuda:0' if cuda else 'cpu') def time_synchronized(): if torch.cuda.is_available(): torch.cuda.synchronize() return time.time()
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值