2015年12月21日 星期一

[Git] Remove useless file from commit history

  1. Clone git from git repository
    git clone https://github.com/XXXX.git

  2. cd XXXX

  3. Remove
[freeman@localhost snmp]$ git filter-branch --force --index-filter \
> 'git rm --cached --ignore-unmatch     happy/good/*.pdf' \
> --prune-empty --tag-name-filter cat -- --all 
Rewrite 3c970f1a6def691845f26a4dae0522a9edfcaa23 (8/8)rm 'happy/good/doc/haha.pdf'

Ref 'refs/heads/EVW3226-211_SNMP_Trap_feature_request' was rewritten
WARNING: Ref 'refs/heads/master' is unchanged
Ref 'refs/remotes/origin/EVW3226-211_SNMP_Trap_feature_request' was rewritten
WARNING: Ref 'refs/remotes/origin/master' is unchanged
WARNING: Ref 'refs/remotes/origin/master' is unchanged



4. Clean cache and recycle space

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



5. Force to commit
git push origin master –force



Reference”

0 意見:

張貼留言