当前位置: 首页 > news >正文

去除GIT某个时间之前的提交日志

背景

有时git提交了太多有些较早之前的提交日志,不想在git log看到,想把他删除掉。

方法

大概思路是通过 git clone --depth 来克隆到指定提交的代码,此时再早之前的日志是没有的

然后提交到新仓库

#!/bin/bash
ori_git="git@your.git.path/ori-prj.git"   #源仓库
ori_branch="master" 
ori_path="ori-prj"dest_git="git@your.git.path/dest-prj.git" #需要提交到变更后的仓库
dest_branch="master"
dest_path="dest-prj"
previous_commit="41059bbcc349de4faccf484326a94d3c816cdd05" #从哪个id开始拉,不包含当前idif [ -d "$ori_path" ]; thenecho "$ori_path exist"
elseecho "git clone $ori_git --branch=$ori_branch $dest_path"git clone $ori_git --branch=$ori_branch $ori_path
ficd $ori_path
git pull
#判断分支是否存在, 没有的话拉一下
if test -z "$(git branch |grep $ori_branch)"; thengit checkout remotes/origin/$ori_branch -b $ori_branch
fi
git checkout $ori_branch# 获取id对应的深度
current_commit=$(git rev-parse HEAD)
commit_count=$(git log --oneline $previous_commit..$current_commit | wc -l)echo $commit_countcd ..
#只克隆到指定id的提交记录
rm -rf $dest_path
git clone $ori_git --depth=$commit_count  --branch=$ori_branch $dest_path
cd $dest_path
git filter-branch -- --all # 要执行下这命令,不然推不上去
git remote rename origin old-origin
git remote add origin $dest_git
git push origin $ori_branch:$dest_branch --force
echo $ori_branch:$dest_branch
cd ..

http://www.lryc.cn/news/283673.html

相关文章:

  • 4 python快速上手
  • 单元测试-spring-boot-starter-test+junit5
  • CentOS 7上安装Anaconda 详细教程
  • 2023年全球软件架构师峰会(ArchSummit深圳站):核心内容与学习收获(附大会核心PPT下载)
  • RT-Thread Studio学习(十六)定时器计数
  • 【linux进程间通信(一)】匿名管道和命名管道
  • 第11章 jQuery
  • leetcode:1736. 替换隐藏数字得到的最晚时间(python3解法)
  • MySQL存储函数与存储过程习题
  • 基于 Hologres+Flink 的曹操出行实时数仓建设
  • 【Docker】实战多阶段构建 Laravel 镜像
  • 【MATLAB源码-第118期】基于matlab的蜘蛛猴优化算法(SMO)无人机三维路径规划,输出做短路径图和适应度曲线。
  • 【计算机组成与体系结构Ⅱ】Tomasulo 算法模拟和分析(实验)
  • Nginx 简介
  • C++入门学习(一)写一个helloworld
  • ChatGPT 股市知识问答
  • uniapp多端评价页
  • 行为树(Behavior Trees)
  • opensssl BIO方式https客户端
  • JavaScript之判断是否整数、取余、取整、进制、位或、ES6
  • 【打造你自己的Shell:编写定制化命令行体验】
  • PGSQL主键序列
  • pg14.2迁移至KingbaseV8R6后部分表记录数为空
  • 【Spring 篇】深入解析SpringMVC的组件魅力
  • HPsocket 在 C# 中的运用:一款优秀的 socket 通信框架
  • 黑豹程序员-MyBatisPlus封装SQL的where条件的对象 QueryWrapper
  • 每日一题——LeetCode1252.奇数值单元格的数目
  • C#学习笔记3-函数与单元测试
  • osg屏幕事件处理器和状态集操控器学习
  • 中国泛娱乐出海视频字幕解决方案