git patch ignoring white space diffs c++
The only thing I care about is C++ file. (Don’t worry about binary files, text, etc … you can assume taht everything is C++ code_).
I have these branches:
* dev master
Now, I can to create a new branch “magic”, where branch magic is equiv to “dev” (in terms of C++ code generated), but minimizes useless whiteline diffs (like inserting extra newlines) from master.
Is this possible?
3 Solutions collect form web for “git patch ignoring white space diffs c++”
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.
git diff --ignore-space-change ...
You could try setting up a
post-merge hook which will:
- only do anything if the current branch is magic
- remove all whitelines of *.cpp files
- make a new commit (since a
post-mergehook cannot directly affect the outcome of