meta data for this page
  •  

This is an old revision of the document!


Rewrite history

reword commits

Automatically reword all rebased commits

Following will automatically execute default editor for every commit:

git rebase origin/master -x 'git commit --amend'

Remove files from history (rewriting)

Iterate through history and remove all files mathcing pattern:

git filter-branch --tree-filter 'rm -f m* z* x* w* s* r*' --prune-empty  HEAD
sudo apt install git-filter-repo

Remove workspace dir:

git filter-repo --path workspace --invert-paths --force

Move from subdir to root

git filter-repo --path-rename 'MYDIR/:'

Move from root to subdir

git filter-repo --path-rename ':app/'

apply dos2unix

git filter-branch --tree-filter 'git ls-files -z | xargs -0 dos2unix' -- --all

clean backups refs

filter-branch makes backup by creating refs/oribinal/*. To clean all backups refs from rewriting history tools:

git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git for-each-ref --format="%(refname)" refs/replace/ | xargs -n 1 git update-ref -d