Gstar666 commited on
Commit
ab9aa70
·
1 Parent(s): 71479fc
Files changed (1) hide show
  1. up.sh +69 -0
up.sh ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # 检查是否在 Git 仓库中
4
+ if [ ! -d ".git" ]; then
5
+ echo "Error: This is not a Git repository."
6
+ exit 1
7
+ fi
8
+
9
+ # 配置仓库以支持大文件上传(如果尚未配置)
10
+ huggingface-cli lfs-enable-largefiles .
11
+
12
+ # 获取当前目录下的所有未跟踪文件
13
+ untracked_files=$(git status --porcelain | grep '??' | awk '{print $2}')
14
+
15
+ # 检查是否有未跟踪的文件
16
+ if [ -z "$untracked_files" ]; then
17
+ echo "No untracked files to add."
18
+ exit 0
19
+ fi
20
+
21
+ # 已处理文件的记录文件
22
+ processed_files=".processed_files.log"
23
+
24
+ # 初始化记录文件(如果不存在)
25
+ if [ ! -f "$processed_files" ]; then
26
+ touch "$processed_files"
27
+ fi
28
+
29
+ # 重试次数
30
+ max_retries=10
31
+
32
+ # 遍历每个未跟踪的文件
33
+ for file in $untracked_files; do
34
+ if grep -Fxq "$file" "$processed_files"; then
35
+ echo "$file has already been processed. Skipping."
36
+ continue
37
+ fi
38
+
39
+ if [ -f "$file" ]; then
40
+ echo "Adding $file to the repository..."
41
+
42
+ # 添加文件
43
+ git add "$file"
44
+
45
+ # 提交更改
46
+ git commit -m "Add $file"
47
+
48
+ # 推送更改,带重试机制
49
+ retry_count=0
50
+ while [ $retry_count -lt $max_retries ]; do
51
+ if git push; then
52
+ echo "$file has been pushed to the repository."
53
+ echo "$file" >> "$processed_files"
54
+ break
55
+ else
56
+ echo "Failed to push $file. Retrying ($((retry_count+1))/$max_retries)..."
57
+ retry_count=$((retry_count+1))
58
+ sleep 5 # 等待 5 秒后重试
59
+ fi
60
+ done
61
+
62
+ if [ $retry_count -eq $max_retries ]; then
63
+ echo "Failed to push $file after $max_retries attempts. Exiting."
64
+ exit 1
65
+ fi
66
+ fi
67
+ done
68
+
69
+ echo "All untracked files have been processed."