我想用一年的提交來清理回購的歷史,總共大約 4000 次。
一位貢獻者一直不同意格式化標準并反復更改 Prettier 組態檔,或者根本不使用 Prettier。因此,git 歷史是一種外觀變化的拉鋸戰,差異巨大,很難找到真正的變化。
前端目錄的名稱在某個時候被重命名。我們從該目錄中加載專案,這使得從 VSCode 訪問早期的 git 歷史記錄變得很麻煩。
在某個時候添加了一個 TypeScript 轉譯器,為整個專案生成一個
file.jsand 。這些檔案的生成不一致(有時它們最后有特定的注釋,有時沒有),這增加了 git 歷史記錄中的噪音。file.js.mapfile.ts
我的暫定計劃是重新設定所有內容:
為了以防萬一,我將保留 repo 的備份,然后重新設定基準,在每次提交時執行以下操作:
- 應用一致的 Prettier 設定;
- 必要時重命名前端目錄;
- 洗掉所有不必要的
file.js和file.js.map檔案。
然后我們的團隊將轉移到新的倉庫。
具體來說:
GIT_SEQUENCE_EDIT=cat git rebase
--strategy recursive --strategy-option theirs --rebase-merges \
--exec '../cleanup.sh && git add . && git commit --amend --no-edit --no-verify --allow-empty' \
e709bcd1
使用e709bcd1腳本的 SHA 是一個好的起點cleanup.sh:
#! /usr/bin/env zsh
setopt nullglob
echo $(git rev-parse HEAD) > commit.log
# If both directories exist, assume old_front_end is the real one,
# so delete new_front_end to allow us to rename old_front_end.
# (Otherwise, `mv` will move the one directory into the other.)
if [[ -d "old_front_end" ]] && [[ -d "new_front_end" ]]; then
rm -rf new_front_end
fi
# Rename old_front_end if necessary
if [[ -d "old_front_end" ]] && [[ ! -d "new_front_end" ]]; then
mv old_front_end new_front_end
fi
if [[ -d "new_front_end" ]]; then
# Clean up JS files
for file in "new_front_end/src/**/*.ts"; do
[[ ! -e $file ]] && continue # skip following if no such file
rm "${file%.*}.js"
rm "${file%.*}.js.map"
done
# Apply consistent Prettier settings
prettier --config ~/external_source_of_truth/.prettierrc -w "new_front_end/src/**/*.{js,ts,svelte,gql,css,scss}" || true
fi
問題:
- 我沒有太多的 rebase 或撰寫 shell 腳本的經驗。這是一個合理的計劃嗎?會不會產生不幸的后果?
- 我試過運行腳本,但它經常因合并沖突而卡住。似乎我總是可以通過做來解決沖突
git add . && git rebase --continue,但我寧愿不必這樣做數百次。我可以自動化嗎?
uj5u.com熱心網友回復:
兩個問題的答案:
似乎足夠合理。
使用
git filter-repo和相關工具解決lint-history:
重命名前端目錄:
git filter-repo --path-rename old_front_end/:new_front_end/
清理 JS 檔案:
git filter-repo --force --filename-callback '
if filename.endswith(b".js"):
ts_file = filename[:-3] b".ts"
if os.path.isfile(ts_file.decode("utf-8")):
return None
if filename.endswith(b".js.map"):
ts_file = filename[:-7] b".ts"
if os.path.isfile(ts_file.decode("utf-8")):
return None
return filename
'
更漂亮
lint-history --relevant '
return filename.endswith(b".ts") or filename.endswith(b".js")
or filename.endswith(b".svelte") or filename.endswith(b".css")
or filename.endswith(b".scss") or filename.endswith(b".gql")
' --filenames-important maybe-prettier
我需要撰寫一個名為的幫助程式腳本,maybe-prettier因為某些提交包含帶有未解決的合并符號(<<<<<<<< HEAD等等)的錯誤檔案。Prettier 無法格式化這些檔案并出現錯誤退出,停止了filter-repo. 為了解決這個問題,maybe-prettier首先檢查檔案是否能夠被格式化;它總是成功退出。
也許更漂亮
#! /usr/bin/env zsh
# Prettier gives three exit codes:
# 0 file is good
# 1 needs formatting
# 2 error
prettier --config ~/external_source_of_truth/.prettierrc -c $1
if [[ $? = 1 ]]; then
prettier --config ~/external_source_of_truth/.prettierrc -w $1
fi
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/531309.html
標籤:混帐变基更漂亮
上一篇:以編程方式將當前分支插入命令
