I created a test branch on a master branch and made some commits on it. Among these commits there were auto-formatting changes. So when I type
git diff master test
I can see almost every line with old formatting removed (- in red) and added (+ in green) a new line with a new formatting.
I would like to keep my changes on a test branch but I would like to restore the old formatting. Is that even possible? Does git know which new lines correspond to the old lines? If the line was modified it would be easy to do, but git diff displays it as a removed and then an added line – like they had nothing in common in git’s mind.
I tried various merge strategies, but it seems that this problem needs something more.
Small hint. If you want to view diff between two banches ignoring whitespace changes use
git diff -binstead ofgit diff.Back to your question. It is really depends on how changes were committed. If you committed useful improvements and reformatting separatly, then it is possible to revert reformattings. You just need to revert one or several commits. Otherwise I don’t think it is possible to do automatcly. Thow there are several options in git diff you can find youseful.