Your question is not entirely clear to me. I think you want the new branch to contain a number of commits that are "equivalent" to those in dev but do not contain unnecessary changes to spaces.
The easiest way to do this is git rebase --interactive . This allows you to manually edit a series of commits. You can get the hash of the first ("root") commit with git rev-list HEAD | tail -n 1 git rev-list HEAD | tail -n 1 . If you want to edit the first commit as well, it's harder, but there is an SO answer for that.
git checkout dev git checkout -b magic git rebase --interactive $(git rev-list HEAD | tail -n 1)
This calls the editor in the commit list in direct chronological order. You change the selection for editing on the commits you want to change. git then pauses until each of these commits is processed, allowing you to change it with git commit --amend , and then continue rebase with git rebase --continue . Of course, you can run the script to clean the files, and not to edit them manually. If you want to do this depending on the differences from the previous commit, you will need to use something like git cat-file blob HEAD^:filename to retrieve the previous version or use git diff HEAD^ filename .
If you want to automate the whole process, you can use the git filter-branch --tree-filter script . See the man page for git-filter-branch for more details.
If you want future commits to not contain errors in the form of spaces, you can configure hook hooks to prevent them.
Once you are 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 can cause problems for people who already have a copy of dev in their own repositories. Then it would be better to merge.
source share