git+python 生成指定版本之间增量差异源代码包

首先拿到需要比较版本的git 的   id

vscode可以在时间线找

xxx是你的id,旧版本

head是 新版本

然后在终端执行  

git diff xxx head --name-only > diff.txt

执行python导出

import os
import shutil
import chardet

# 定义源目录和目标目录
source_dir = 'D:/work/cqsp-service-web'  # 替换为你的源目录路径
destination_dir = 'C:/Users/86150/Desktop/cqsp-service-web'  # 替换为你的目标目录路径

# 定义要复制的文件列表
# 初始化文件列表
files_to_copy = []

# 使用原始字符串指定diff.txt文件的完整路径
diff_file_path = 'D:/work/cqsp-service-web/diff.txt'

try:
    # 检测文件编码
    with open(diff_file_path, 'rb') as f:
        raw_data = f.read()
        result = chardet.detect(raw_data)
        encoding = result['encoding']

    # 打开并读取diff.txt文件
    with open(diff_file_path, 'r', encoding=encoding) as file:
        # 逐行读取文件内容
        for line in file:
            # 去除每行的首尾空白字符(包括换行符)
            file_path = line.strip()
            # 将文件路径添加到列表中
            files_to_copy.append(file_path)

    # 打印结果,查看files_to_copy列表内容
    print(files_to_copy)
except FileNotFoundError:
    print(f"文件未找到,请检查路径:{diff_file_path}")
except Exception as e:
    print(f"发生错误:{e}")

# 如果目标目录不存在,则创建它
if not os.path.exists(destination_dir):
    os.makedirs(destination_dir)

# 遍历文件列表,复制每个文件到目标目录
for file_name in files_to_copy:
    full_file_name = os.path.join(source_dir, file_name)  # 构建源文件的完整路径
    destination_file_name = os.path.join(destination_dir, file_name)  # 构建目标文件的完整路径

    # 获取目标文件的目录
    destination_file_dir = os.path.dirname(destination_file_name)

    # 确保目标文件的目录存在,如果不存在,则创建它
    if not os.path.exists(destination_file_dir):
        os.makedirs(destination_file_dir)

    # 确保源文件存在
    if os.path.isfile(full_file_name):
        shutil.copy(full_file_name, destination_file_name)  # 复制文件
        print(f"Copied {file_name} to {destination_dir}")
    else:
        print(f"File {file_name} not found in {source_dir}. Skipping...")

print("File copying complete.")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码老祖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值