Your question isn't completely clear to me. I think you want the new branch to contain series of commits that are "equivalent" to the ones in dev but don't contain unnecessary whitespace changes.
The simplest way to do this is with git rebase --interactive
. This allows you to edit a series of commits manually. You can get the hash of the first ("root") commit with git rev-list HEAD | tail -n 1
. If you want to edit the first commit as well, that's more difficult but there's a SO answer for that.
git checkout dev
git checkout -b magic
git rebase --interactive $(git rev-list HEAD | tail -n 1)
This brings up an editor on the list of commits in forward chronological order. You change pick to edit on the commits that you wish to change. git will then pause before processing each of these commits, allowing you to modify it with git commit --amend
and then continue the rebase with git rebase --continue
. You could of course run a script to clean up the files rather than editing them manually. If you want to do this based on the differences from the previous commit you would need to use something like git cat-file blob HEAD^:filename
to fetch the previous revision, or use git diff HEAD^ filename
.
If you want to automate the whole process then you can use git filter-branch --tree-filter script
. Look at the man page for git-filter-branch for details.
If you want to prevent future commits from containing whitespace errors, you can set up a pre-commit hook to disallow them.
Once you're happy with the new branch magic you can use it to replace dev:
git branch -m dev dev-old
git branch -m magic dev
However, note that this might cause problems for people who already have a copy of dev in their own repos. It would then be better to do a merge instead.