Xz's blog Xz's blog
首页
时间序列
多模态
合成生物学
其他方向
生活
工具相关
PyTorch
导航站

Xu Zhen

首页
时间序列
多模态
合成生物学
其他方向
生活
工具相关
PyTorch
导航站
  • Rust

  • Docker

  • VMware虚拟机

  • Python常用代码片段

    • 打印Git信息
  • 工具相关
  • Python常用代码片段
xuzhen
2025-07-17

打印Git信息

import subprocess

def run_git_cmd(args):
    try:
        return subprocess.check_output(['git'] + args).decode().strip()
    except subprocess.CalledProcessError:
        return "N/A"

def get_git_info():
    info = {
		"Branch": run_git_cmd(['rev-parse', '--abbrev-ref', 'HEAD']),
		"Commit Hash": run_git_cmd(['rev-parse', 'HEAD']),
		"Short Hash": run_git_cmd(['rev-parse', '--short', 'HEAD']),
		"Author": run_git_cmd(['log', '-1', '--pretty=format:%an <%ae>']),
        "Date": run_git_cmd(['log', '-1', '--pretty=format:%ad']),
        "Message": run_git_cmd(['log', '-1', '--pretty=format:%s']),
        "Remote": run_git_cmd(['remote', '-v']),
        "Status": run_git_cmd(['status', '--short']),
	    }
    print("Git Information:")
    for k, v in info.items():
        print(f"{k:12}: {v}")
        
get_git_info()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#Python
上次更新: 2025/07/18, 09:51:17

← VMware的Ubuntu虚拟机无法拖拽文件

最近更新
01
Slice切片
07-26
02
引用与借用
07-26
03
所有权
07-26
更多文章>
Theme by Vdoing | Copyright © 2025-2025 Xu Zhen | 鲁ICP备2025169719号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式