zoukankan      html  css  js  c++  java
  • gitlab重写历史,清理历史大文件

    1.导出gitlab上原仓库作为备份。

    2.克隆远端仓库代码

    git clone http://ip/group/repo.git
    cd repo.git

    3.拉取仓库的所有分支

    git branch -r | grep -v '->' | while read remote;do git branch --track 
    "${remote#origin/}" "$remote";done
    git branch
    git tag
    git fetch --all
    git pull --all

    [4.]查找历史大文件(若是知道具体的大文件,不需要查)

         将最大的10个文件查询出来:

    git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx 
    | sort -k 3 -n | tail -10 | awk '{print $1}')"

    4.处理记录

    git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch 文件或
    目录' --prune-empty --tag-name-filter cat -- --all
    提示:此过程会在项目根目录生成".git_……"文件夹,里面就是改的记录,且一次只能清理一个文件夹或者文件

    5.回收空间

    git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
    rm -rf .git/refs/original/
    git reflog expire --expire=now --all
    git gc --prune=now
    git gc --aggressive --prune=now

    6.删除原仓库,新建原仓库的同名仓库,重新关联已清理的仓库,直接推送。

    git remote set-url origin http://ip/group/repo.git
    git remote -v
    git push origin --all
    git push origin --tags

    至此,垃圾清理完成。

    注意:下次开发时需要重新拉取git仓库上的代码,否则还会引入之前大文件的历史记录。

  • 相关阅读:
    零散的小知识0
    windows 安装touch指令
    sba
    jQuery中mouseenter vs mouseover 以及 mouseleave vs mouseout
    SSAS: Pareto Analysis
    SSAS: Display measures in Rows
    SSAS: Using DMV Queries to get Cube Metadata
    Do not execute sub-report when it's hidden in SSRS
    Read data from Excel XML file
    Concatenating Row Values in Transact-SQL
  • 原文地址:https://www.cnblogs.com/schblog/p/14033212.html
Copyright © 2011-2022 走看看