shari-sushi / 0015Laboratory

My SandBox, PoC
0 stars 0 forks source link

git-filterの動作テスト #4

Open shari-sushi opened 8 months ago

shari-sushi commented 8 months ago

〇目的 ・「gitignoreし忘れてpushしてしまい、気づくまでにpushを重ねてしまった」を想定した対処方法を試す。

〇参考 git最強のオプション filter

git push --forceで履歴は消えないと言う話

shari-sushi commented 8 months ago

コミット履歴作成 ーーーーーーーーーーー 1st ・go install→go.mod生成 ・.env作成(.gitignoreしなかった)

mainブランチ 10137ba3557dfdde274c6ea19123d94c9f194c90 pullリク https://github.com/sharin-sushi/0015docker/pull/5#issue-2000205406

image .envがgitに表示されてしまっている。 ーーーーーーーーーーー 2nd ・main.gofmt.Print("2nd commit at issue4 ")追記 3rd ・main.gofmt.Print("3rd commit at issue4 ")追記 4th ・main.gofmt.Print("4th commit at issue4 ")追記

2nd~4thをまとめてpush c4ad679 ーーーーーーーーーーー 5tn? さらに別のファイル編集をコミット b7bd2f273b5ad6224e36a0bbf52190b3c4a6a614 pushした。pull riquestはしてない。

shari-sushi commented 8 months ago

git-filter実行

0015Docker> git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch test0015Go.env" --prune-empty -- --all
WARNING: git-filter-branch has a glut of gotchas generating mangled history
         rewrites.  Hit Ctrl-C before proceeding to abort, then use an
         alternative filtering tool such as 'git filter-repo'
         (https://github.com/newren/git-filter-repo/) instead.  See the
         filter-branch manual page for more details; to squelch this warning,
         set FILTER_BRANCH_SQUELCH_WARNING=1.

Proceeding with filter-branch...

Rewrite cc370566cbb543c84a7d1d21d47913e0bc6a5481 (1/17) (0 seconds passed, remaining 0 predicted)   
Rewrite cef91ff030302126ecb36a11f61d2ab8a58f3fa2 (2/17) (0 seconds passed, remaining 0 predicted)   
Rewrite 79771d44c22ee01bae4dfb22de7b8cec1b978361 (3/17) (1 seconds passed, remaining 4 predicted)   
Rewrite 25a05ed4bc3d5f026d30b3acd9692dd5eac40be9 (3/17) (1 seconds passed, remaining 4 predicted)   
Rewrite 2bc5bd8aac313e6d3600e407c998ccd7ebe3426c (3/17) (1 seconds passed, remaining 4 predicted)   
Rewrite db46b65c20777cae12b3beb5f9cf181216bf2929 (3/17) (1 seconds passed, remaining 4 predicted)   
Rewrite a6c1857278d9da0f34ec826a6da269e5aedcb836 (7/17) (3 seconds passed, remaining 4 predicted)   
Rewrite 5091537aa7b6a1a18ff42c063cfabe91f00ddf1f (7/17) (3 seconds passed, remaining 4 predicted)   
Rewrite 7762ff1eae5368291766b8912e2c502d4408c2e1 (7/17) (3 seconds passed, remaining 4 predicted)   
Rewrite b5ff507c5672f2393d75214aa665197485fa56cf (10/17) (5 seconds passed, remaining 3 predicted)  
Rewrite 7a98458b21058a94bb143ca375b5895d37afcb5a (10/17) (5 seconds passed, remaining 3 predicted)  
Rewrite 97c1bf3f0f4b55bf0a84aae1566f2182ee2ee50f (10/17) (5 seconds passed, remaining 3 predicted)  
Rewrite 10137ba3557dfdde274c6ea19123d94c9f194c90 (13/17) (6 seconds passed, remaining 1 predicted)  
Rewrite 5eef9bf0ef4f6501fe837f8557cff963d903adf4 (13/17) (6 seconds passed, remaining 1 predicted)  
Rewrite dea7969b0b80e38e41c685e6f9046a3bf8a400ef (13/17) (6 seconds passed, remaining 1 predicted)  
Rewrite d452601c4a1746d97f07fe760875068bbe33d82d (16/17) (8 seconds passed, remaining 0 predicted)  
Rewrite b7bd2f273b5ad6224e36a0bbf52190b3c4a6a614 (16/17) (8 seconds passed, remaining 0 predicted)  

Ref 'refs/heads/issue/1-run_npm_run_build_ERR' was rewritten
Ref 'refs/heads/issue/3-commit_editmsg' was rewritten
Ref 'refs/heads/issue/4-git_filter' was rewritten

17個のプルリク?コミット?履歴に影響し、3つ(全部)のブランチが書き換えられたしたらしい。

shari-sushi commented 8 months ago

.envはどこからも消えてませんね。

shari-sushi commented 8 months ago

実行場所がダメなのかと思ったけれど、むしろそこ(ルートディレクトリ)じゃないとダメみたい。

\0015Docker\test0015Go> git filter-branch --index-filter "git rm -rf 
--cached --ignore-unmatch .env" --prune-empty -- --all
fatal: could not open 'test0015Go/nul' for reading: No such file or directory
WARNING: git-filter-branch has a glut of gotchas generating mangled history  
         rewrites.  Hit Ctrl-C before proceeding to abort, then use an       
         alternative filtering tool such as 'git filter-repo'
         (https://github.com/newren/git-filter-repo/) instead.  See the      
         filter-branch manual page for more details; to squelch this warning,
         set FILTER_BRANCH_SQUELCH_WARNING=1.
Proceeding with filter-branch...

You need to run this command from the toplevel of the working tree.
shari-sushi commented 8 months ago

最初に何か失敗してるのかと思ったけれど、そういうわけでも無さそう?

0015Docker> git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch test0015Go.env" --prune-empty -- --all
WARNING: git-filter-branch has a glut of gotchas generating mangled history
         rewrites.  Hit Ctrl-C before proceeding to abort, then use an
         alternative filtering tool such as 'git filter-repo'
         (https://github.com/newren/git-filter-repo/) instead.  See the
         filter-branch manual page for more details; to squelch this warning,
         set FILTER_BRANCH_SQUELCH_WARNING=1.
Proceeding with filter-branch...

Cannot create a new backup.
A previous backup already exists in refs/original/
Force overwriting the backup with -f