Skip to content

Commit

Permalink
chore: being v2.7 - no history on branch website
Browse files Browse the repository at this point in the history
  • Loading branch information
LetMeFly666 committed Jun 11, 2024
1 parent 54a2e7f commit 99d0c74
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Solutions/Other-English-LearningNotes-SomeWords.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ tags: [其他, 知识, 英语, Notes]
|mathematician|n. 数学家|
|inn|n. 客栈,(乡村可夜宿的)小酒店<br/>v. 住旅馆|
|flux|n. 不断的变动,不停的变化,通量,流动|
|||
|maize|n. 玉米|
|vine|n. 藤,藤蔓,藤本植物|

<details>
<summary>扇贝音频测试</summary>
Expand Down
63 changes: 63 additions & 0 deletions archiveHistory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'''
Author: LetMeFly
Date: 2024-06-11 21:59:50
LastEditors: LetMeFly
LastEditTime: 2024-06-11 22:21:22
'''
"""
写一个Python脚本,实现以下功能:
在一个Git仓库中,将每次commit打包成Zip文件。
文件命名格式为对应commit的{日期}{时间}{commitHash}.zip,例如20240622-220603-54a2e7fe41081489e8913436daa7bee5ae878d26.zip
"""
import os
import zipfile
import git
from datetime import datetime
import shutil

def zip_commit(repo_path, commit: git.Commit):
# 提取 commit 日期和时间
print(commit.message)
commit_datetime = datetime.fromtimestamp(commit.committed_date)
date_str = commit_datetime.strftime('%Y%m%d')
time_str = commit_datetime.strftime('%H%M%S')

# 构造 zip 文件名
zip_filename = f"archived/{date_str}-{time_str}-{commit.hexsha}.zip"

# 创建一个临时目录来存储这个 commit 的文件
temp_dir = f"temp"
os.makedirs(temp_dir, exist_ok=True)

# 导出 commit 的文件
repo.git.checkout(commit)
for item in repo.tree().traverse():
if item.type == 'blob': # 确保这是一个文件而不是一个子目录
item_path = os.path.join(repo_path, item.path)
os.makedirs(os.path.dirname(os.path.join(temp_dir, item.path)), exist_ok=True)
with open(item_path, 'rb') as fsrc, open(os.path.join(temp_dir, item.path), 'wb') as fdst:
fdst.write(fsrc.read())

# 打包成 zip 文件
with zipfile.ZipFile(zip_filename, 'w') as zipf:
for root, _, files in os.walk(temp_dir):
for file in files:
zipf.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), temp_dir))

# 清理临时目录
shutil.rmtree(temp_dir)

if __name__ == "__main__":
# 指定你的 Git 仓库路径
repo_path = 'repo'
os.makedirs('archived', exist_ok=True)

# 打开仓库
repo = git.Repo(repo_path)

# 遍历所有的 commit
for commit in repo.iter_commits():
zip_commit(repo_path, commit)

# 切换回默认分支(例如 'main' 或 'master')
repo.git.checkout('master')

0 comments on commit 99d0c74

Please sign in to comment.