命令集合

1.查看特定时间段的提交信息 timedatectl set-time "2021-10-02 13:00:00" git log --since="2021-10-01" --before="2021-10-30" --author="张斌" git log --until="2021-08-01"2.截取commitid创建新的分支 timedatectl set-time "2021-10-02 13:00:00" git checkout master-base commitid=$(git rev-list -1 --before="2021-08-01 00:00:00" HEAD) git checkout -b master-base-temp $commitid3.合并分支 timedatectl set-time "2024-10-02 13:00:00" git checkout master-base-temp git merge master-base 把master-base上的提交记录合并到master-base-temp分支上4.修改最近提交记录 git commit --amend -m "初始化分支代码" --author="管理员 <yxh@.cn>" --date="2023-01-01 11:30:30"
excel按照日期排序脚本

import pandas as pd import random from datetime import datetime#每个月份都要修改一下日期 template_dir="./template.xlsx"df = pd.read_excel(template_dir,sheet_name=0,engine='openpyxl') df_cleaned = df[pd.notna(df['完成日期'])] #删除NaT(Not a Time)的行row_list=[] for index, row in df_cleaned.iterrows():row_list.append({"user":row[7],"giturl":row[10],"gittime":row[11],"tablename":row[12],"copydir":row[13]})tag_list=[] for trow in row_list:if "," in str(trow["gittime"]):ttimes = trow["gittime"].split(",")else:ttimes = [trow["gittime"]]for tindex,time in enumerate(ttimes):tag_list.append({"user":trow["user"],"giturl":trow["giturl"],"tablename":trow["tablename"],"copydir":trow["copydir"],"gittime":time,"main-index":(tindex%len(ttimes))})#这里是按照list中对象的某个属性字段进行排序 sorted_list = sorted(tag_list, key=lambda x: datetime.strptime(str(x["gittime"]).replace("-","/")[:10], '%Y/%m/%d'))df = pd.DataFrame(sorted_list)# 保存Excel文件 df.to_excel("output.xlsx", index=False, engine='openpyxl')
python调用shell

import pandas as pd from datetime import datetime import random import subprocessfile_tokens_path = './gitusers.xlsx'#每个月份都要修改一下日期 template_dir="./2021-07/output.xlsx"#使用pandas的read_excel函数读取Excel文件 df_tokens = pd.read_excel(file_tokens_path,engine='openpyxl')token_dict={} email_dict={}for index,token in df_tokens.iterrows():#token_list.append({"name":token[0],"token":token[3]})token_dict[token[0]]=token[3]if str(token[2])=="nan":email_dict[token[0]]=str(token[1])+".cn"else:email_dict[token[0]]=token[2]msg_list=[] #2.读取提交信息列表模板 with open('./msg.txt', 'r') as file:for line in file:msg_list.append(line.strip().replace("\n", ""))row_list=[] df = pd.read_excel(template_dir,sheet_name=0,engine='openpyxl')for index, row in df.iterrows():row_list.append({"user":row[0],"giturl":row[1],"tablename":row[2],"copydir":row[3],"gittime":row[4],"main-index":row[5]})print("本次需要提交"+str(len(row_list))+"条大记录")success=0 for index,row in enumerate(row_list):if token_dict[row["user"]]:time = str(row["gittime"])time =time.replace("/", "-")print("***************************")print(token_dict[row["user"]])print(time)print(row["giturl"])print(random.choice(msg_list))print(row["user"])print(row["tablename"])print(str(row["main-index"]))print(email_dict[row["user"]])print(row["copydir"])print("***************************")result = subprocess.run(['sh', 'gitshell.sh', token_dict[row["user"]], time,row["giturl"],random.choice(msg_list),row["user"],row["tablename"],str(row["main-index"]),email_dict[row["user"]],row["copydir"]])if result.returncode !=0:print(row["user"]+"在"+time+"提交一次代码失败")with open('userfailpush.txt', 'a') as file:file.write(row["user"]+" "+token_dict[row["user"]]+" "+row["giturl"]+" "+time+" "+str(success)+"/"+str(totalpushs)+"\r\n")else:print(row["user"]+"在"+time+"成功提交一次代码")success=success+1print("\033[91m成功提交第"+str(success)+"/"+str(len(row_list))+"次代码\033[0m")else:print(row["user"]+"用户不存在")with open('soarusers.txt', 'a') as file:file.write(row["user"]) print("本次任务一共提交"+str(success)+"条记录")
shell操作git接口

#!/bin/bash################################################ #提交月代码 ###############################################token=$1 time=$2 gitrepo=$3 gitmsg=$4 username=$5 tablename=$6 dirname=$7 emailname=$8 copydir=$9#这里需要按照项目修改 prodir="/home/admin/evan-data/csam/b-front/b-front/" codedirs="/home/admin/evan-data/csam/b-front/" month="2021-07"giturl=`echo "${gitrepo#https://}"` res=https://oauth2:$token@$giturl.git cd $prodir git config user.name $username git config user.email $emailnamecodedate=$codedirs$month trimtablename=$(echo "$tablename" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') echo "***************************" echo "进入main-"$dirname"目录搜素文件" echo $trimtablename echo $codedate/main-$dirname echo "***************************"rm -fr /tmp/gitfiles.txt codedate=$codedirs$monthfind $codedate/main-$dirname -name $trimtablename"*" >> /tmp/gitfiles.txtfile="/tmp/gitfiles.txt" # 获取总行数 total_lines=$(wc -l < "$file") current_line=1 batch=1 min_hour=8 count=0 echo "===== 开始读取文件: $file (共 $total_lines 行) =====" while [ $current_line -le $total_lines ]; do# 生成随机批次大小(在min_batch和max_batch之间)# batch_size=$((RANDOM % (max - min + 1) + min))batch_size=$(( RANDOM % (4-1+1) + 1 ))count=$((count + 1))# 计算实际可读取的行数remaining=$(( total_lines - current_line + 1 ))if [ $batch_size -gt $remaining ]; thenbatch_size=$remainingfi# 显示批次信息printf "批次 %3d: 读取 %2d 行 (剩余: %4d/%4d)\n" \$batch $batch_size $((total_lines - current_line + 1)) $total_lines# 读取指定行范围sed -n "${current_line},$((current_line + batch_size - 1))p" "$file" | tee /tmp/gitlines.txtwhile IFS= read -r line; dotempdir=$(echo $line | sed 's#/'$month'\/main-[0-9]#/iesmp-front/'$copydir'#')dstfile=$(echo $tempdir | sed 's/\/\{2\}/\//g')mydirname=$(dirname "$dstfile")mkdir -p $mydirnamecp -r $line $mydirnamedone < /tmp/gitlines.txtgit checkout master-base-tempecho $timeecho "上一次提交的小时"$min_hour add_hour=$((RANDOM % 2 + 1))random_hour=$((min_hour+ 1))if [ $random_hour -gt 23 ]; thenrandom_hour=23fimin_hour=$random_hour# 格式化小时,确保它是两位数(例如09而不是9)formatted_hour=$(printf "%02d" "$random_hour")# 生成随机分钟(00-59)random_minute=$((RANDOM % 60))# 格式化分钟,确保它是两位数formatted_minute=$(printf "%02d" "$random_minute")# 生成随机秒(00-59)random_second=$((RANDOM % 60))# 格式化秒,确保它是两位数formatted_second=$(printf "%02d" "$random_second")# 组合成完整的日期时间字符串(格式为YYYY-MM-DD HH:MM:SS)random_datetime="${time} ${formatted_hour}:${formatted_minute}:${formatted_second}"filename=$codedirs"msg.txt"random_line=$(shuf -n 1 "$filename")cleaned_string=$(echo "$random_line" | tr -d '[:space:]')echo $random_datetimetimedatectl set-ntp falsetimedatectl set-time "$random_datetime"git add .git commit -m $cleaned_stringecho $res# git -c http.sslVerify=false push $res master-base-tempecho "这是"$count"次提交"if [ $? -eq 0 ]; thensleep 3elseecho "git push出现异常"fi# 更新进度current_line=$((current_line + batch_size))batch=$((batch + 1)) done
merge分支

code_endtime="2021-05-01 00:00:00" system_time="2021-05-01" res="https://oauth2:M6@192.168.30.197:8090/base-repo/a.git"###################动态时间配置#####################################git config user.name "管理员" git config user.email "yxh@.cn"git branch -D merge-dev timedatectl set-time "$system_time 12:30:00" git checkout master-dev commitid=$(git rev-list -1 --before="$code_endtime" HEAD) echo $commitid git checkout -b merge-dev $commitid git checkout master-base git merge merge-dev --no-edit git -c http.sslVerify=false push $res master-base echo "成功merge分支并推送master-base分支"
实现git操作脚本化