{"id":22768796,"url":"https://github.com/weitsunglin/svn-to-git-solution","last_synced_at":"2025-03-30T11:17:01.397Z","repository":{"id":232504667,"uuid":"784518190","full_name":"weitsunglin/svn-to-git-solution","owner":"weitsunglin","description":"提供從svn挪檔案到git的解決方案","archived":false,"fork":false,"pushed_at":"2024-06-06T03:06:57.000Z","size":278,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T10:47:10.936Z","etag":null,"topics":["batch-script","git","shell-script","svn"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weitsunglin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-10T02:14:33.000Z","updated_at":"2024-10-31T15:51:00.000Z","dependencies_parsed_at":"2024-05-10T05:26:46.911Z","dependency_job_id":"7672a2e8-8144-4696-9ce0-2dad5dc04b3d","html_url":"https://github.com/weitsunglin/svn-to-git-solution","commit_stats":null,"previous_names":["weitsunglin/svn-to-git-largefile-solution"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weitsunglin%2Fsvn-to-git-solution","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weitsunglin%2Fsvn-to-git-solution/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weitsunglin%2Fsvn-to-git-solution/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weitsunglin%2Fsvn-to-git-solution/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weitsunglin","download_url":"https://codeload.github.com/weitsunglin/svn-to-git-solution/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246308047,"owners_count":20756482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["batch-script","git","shell-script","svn"],"created_at":"2024-12-11T14:12:55.436Z","updated_at":"2025-03-30T11:17:01.364Z","avatar_url":"https://github.com/weitsunglin.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"## SVN 搬移 REPO 到 GIT 扼要\n1. 基於svn url 用 git clone 建 repo (如果該repo歷史紀錄太多，可選擇從指定revision clone到git repo)\n2. 設定git remote (svn-git remote再第一步驟會幫你建好)\n3. 從svn clone repo下來通常預測會是master，要手動將其改成main (Browse references中查看)\n4. git push origin main 會遇到一些問題\n   1.大檔案\n   2.太多檔案\n   3.過去單次commit紀錄過大\n6. 如svn有新commit (git svn fetch → git svn rebase → git push)\n   1.可指定revision\n\n## Git clone svn repo\n\n![git clone svn](https://github.com/weitsunglin/svn-to-git-solution/blob/main/git%20clone%20svn%20repo.jpg)\n\n\n## Git local repo設定 remote 目標\n\n![remote setting](https://github.com/weitsunglin/svn-to-git-solution/blob/main/remote%20setting.jpg)\n\n## .git config 檔案中 設定 git-svn 路徑\n提供三種範例\n```\n[svn-remote \"svn\"]\n\turl = http://192.168.1.183/svn/SouthPark\n\tfetch = trunk:refs/remotes/origin/main\n```\n```\n[svn-remote \"svn\"]\n\turl = http://192.168.1.183/svn/Casino/trunk\n\tfetch = :refs/remotes/origin/main\n```\n```\n[svn-remote \"svn\"]\n\turl = http://192.168.1.183/svn/ManganDahen\n\tfetch = branches/Release:refs/remotes/origin/main\n```\n \n## 尋找大型檔案\n\n如果出現在.git中的大型檔案，代表歷史紀錄中曾有過大型檔案 \u003cbr\u003e\n如果出現在專案中其餘路徑，代表現在還存在著大型檔案 \u003cbr\u003e\n可自行替換 folder_path  \n```bat\n@echo off\nsetlocal enabledelayedexpansion\n\nset \"folder_path=F:\\_project\\tmd_1.0\\tmd_on_git\\TMDC_Boost\"\nset \"min_size=104857600\"\n\necho find 100mb file:\nfor /r \"%folder_path%\" %%F in (*.*) do (\n    set size=%%~zF\n    if !size! geq %min_size% echo %%F !size! bytes\n)\n\npause\n```\n\n## Git LFS 使用指南\n\n當開發項目中需要處理大型檔案時，Git LFS（Large File Storage）提供了一種高效的管理方式。\u003cbr\u003e\n這裡介紹三個主要的 Git LFS 相關操作，幫助你更好地管理項目中的大型檔案。\n\n1. 追踪新的大型檔案\n在項目開始階段或當你需要開始追踪新類型的大型檔案時，可以使用 git lfs track 命令。\u003cbr\u003e\n這個命令將指定的檔案或檔案類型加入到 Git LFS 的追踪列表中。\n\n例如，要追踪 example.txt 文件，可以使用以下命令：\n\n```bat\ngit lfs track ‘example.txt’\n```\n\n這樣，每當你提交這些文件時，Git LFS 會處理這些大型檔案，而不是將它們直接儲存在 Git 倉庫中。\n\n2. 導入現有的大型檔案到 Git LFS\n如果你的倉庫歷史中已經包含了大型檔案，而你想要開始使用 Git LFS 來更有效地管理這些文件，而不是徹底移除它們，可以使用 git lfs migrate import 命令。\n\n這個命令允許你指定要導入到 Git LFS 的文件或文件類型，並重新寫入倉庫歷史，以便這些文件由 Git LFS 管理。\n\n例如，要導入example.txt,example2.txt到 Git LFS，可以使用以下命令：\n\n```bat\ngit lfs migrate import --include=\"example.txt,example2.txt\" --everything\n```\n\n3. 從倉庫歷史中移除大型檔案\n如果你想要徹底從倉庫歷史中移除某些文件或數據，使其好像從未被提交過一樣，git filter-repo 是一個非常有用的工具。\n\n這個命令提供了一種方式來清理倉庫歷史，包括徹底移除大型檔案或敏感數據。\n\n例如，要從歷史中移除 example.txt 檔案，可以使用以下命令：\n\n```bat\ngit filter-repo --path example.txt --invert-paths --force\n```\n\n以上介紹的三個操作是使用 Git LFS 管理大型檔案的基礎，幫助你有效地處理和維護項目中的大型檔案。\n\n\n## 批次上傳檔案\n\n如果單次Push超過2GB，可使用批次Push功能。\u003cbr\u003e\ncd TMDC_Inanna 可自行替換路徑。\n```bat\n@echo off\ncd TMDC_Inanna \n\n:: 生成commit-list.txt，每10個提交紀錄一次\ngit rev-list --topo-order --reverse HEAD \u003e temp_commit_list.txt\nsetlocal EnableDelayedExpansion\nset /a \"line=0\"\nset /a \"count=0\"\n\nfor /F \"tokens=*\" %%A in (temp_commit_list.txt) do (\n    set /a \"line+=1\"\n    set /a \"mod=line %% 10\"\n    if !mod! equ 0 (\n        echo %%A \u003e\u003e commit-list.txt\n    )\n)\ndel temp_commit_list.txt\necho rev-list rev-list\n\n:: 遍歷commit-list.txt中的每個提交\nfor /F \"tokens=*\" %%B in (commit-list.txt) do (\n    git reset --hard %%B\n    git push origin ReleaseWindows\n    echo Current SHA: %%B\n)\n\npause\n\n```\n\n``` sh \n#!/bin/bash\n\n# 进入项目目录\ncd /path/to/TMDC_Inanna\n\n# 生成commit-list.txt，每10个提交记录一次\ngit rev-list --topo-order --reverse HEAD \u003e temp_commit_list.txt\n\nline=0\ncount=0\n\n# 读取临时提交列表，并每10个提交保存一次到 commit-list.txt\nwhile IFS= read -r commit; do\n    ((line++))\n    mod=$((line % 10))\n    if [ \"$mod\" -eq 0 ]; then\n        echo \"$commit\" \u003e\u003e commit-list.txt\n    fi\ndone \u003c temp_commit_list.txt\n\n# 删除临时文件\nrm temp_commit_list.txt\necho \"rev-list completed\"\n\n# 遍历commit-list.txt中的每个提交\nwhile IFS= read -r commit; do\n    git reset --hard \"$commit\"\n    git push origin ReleaseWindows\n    echo \"Current SHA: $commit\"\ndone \u003c commit-list.txt\n\n# 暂停等待用户输入（模拟 Windows 批处理中的 pause 命令）\nread -p \"Press enter to continue...\"\n```\n\n## 不斷地從svn撈進度push到git repo\n\n```bat\n@echo off\nset PROJECT_PATH=F:\\_project\\tmd_1.0\\tmd_on_git\n\nfor /d /r \"%PROJECT_PATH%\" %%d in (*) do (\n    if exist \"%%d\\.git\" (\n        echo Found .git in: %%d\n        cd /d %%d\n        git --version\n        :: git svn fetch -r2074:HEAD 從指定svn revision fetch 修訂歷史 到 git \n        git svn fetch\n        git svn rebase\n        for /f \"tokens=*\" %%b in ('git branch --show-current') do set branch=%%b\n        git push origin %branch%\n    )\n)\n```\n```sh\n#!/bin/bash\n\n# 設定項目路徑\nPROJECT_PATH=\"/path/to/your/project\"\n\n# 變例目錄下的所有文件夹\nfind \"$PROJECT_PATH\" -type d | while read -r dir; do\n    if [[ -d \"$dir/.git\" ]]; then\n        echo \"Found .git in: $dir\"\n        cd \"$dir\" || exit\n        git --version\n        git svn fetch\n        git svn rebase\n        branch=$(git branch --show-current)\n        git push origin \"$branch\"\n    fi\ndone\n\necho \"END\"\n```\n\n\n## 常用指令\n1. 從某地方複製資料夾到目的地: xcopy F:\\_project\\tmd_1.0\\tmd_on_git\\MisrSlot F:\\_project\\tmd_1.0\\tmd_on_git\\lfs-backup\\MisrSlot\\ /E /I /H /K\n2. 砍路徑中的資料夾: rd /s /q \"F:\\_project\\tmd_1.0\\tmd_on_git\\lfs-backup\"\n3. 移除最新的commit紀錄: git reset --hard HEAD~1\n\n\n## 注意事項 (要看)\n1. git clone svn 的 repo 預設的分支會是master，可將其改成main再push。\n2. 再github上建立repo時，先別建README.md，目的是讓歷史紀錄保持乾淨，這樣再跟svn repo合併時，才不會產生歷史紀錄不一致的問題。\n3. 遇到單次commit過大，可調整緩衝區大小 git config --global http.postBuffer 524288000 (提高git commit 緩衝區大小: 500mb)。\n4. 可以不用上傳.gitattributes，因為要讓歷史紀錄保持乾淨，亦即跟svn一樣。\n5. 遇到 pull遇到 fatal: refusing to merge unrelated histories。使用git pull origin main --allow-unrelated-histories。強制合併兩個不同的歷史紀錄。但不建議這樣做，盡量保持一致。\n6. 如果有對某一個github repo做lfs操作，要將其執行lfs push，以免github上的repo少了lfs的檔案。\n7. 用mac搬repo，會快很多。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweitsunglin%2Fsvn-to-git-solution","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweitsunglin%2Fsvn-to-git-solution","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweitsunglin%2Fsvn-to-git-solution/lists"}