0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

過去のコミットの変更にある任意の文字を全て消す方法【メモ】

Posted at

経緯

チームの研修資料をGitHubで公開していたところ、研修資料の中に学校名が入ってしまっていたため、それを消すために方法を調査した。

環境

WSL2

別リポジトリを用意

bash
cd /path/to/your/repo
git clone . ../repo-test
cd ../repo-test
# ここで以降のコマンドを実行する

filter-repo が入っていない場合インストール

bash
pip install git-filter-repo

履歴を書き換える

bash
git filter-branch --force \
  --msg-filter 'sed "s/<置き換えたい文字列>/<置き換え後の文字列>/g"' \
  --tree-filter 'git ls-files -z | xargs -0 -n1 sed -i "s/<置き換えたい文字列>/<置き換え後の文字列>/g" || true' \
  --tag-name-filter cat -- --all

古い参照・キャッシュを掃除(履歴書き換え後は必須)

bash
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now --aggressive

force push する

オリジナルの設定が消えていたら、git remote add origin <gitURL> コマンドで設定しなおす。

bash
git push origin --force --all
git push origin --force --tags
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?