GIT: restore formatting from master branch but keep non-formatting changes
Asked Answered
D

1

6

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.

Dropping answered 20/7, 2012 at 0:2 Comment(0)
N
2

Small hint. If you want to view diff between two banches ignoring whitespace changes use git diff -b instead of git 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.

Now answered 20/7, 2012 at 0:41 Comment(2)
Thanks for the answer. So it seems to me that what I would like to do is not possible in a straightforward way with git only. Commits included formatting together with useful changes, these were not separated. The trouble is that the formatting is not just a whitespace (-b) issue, it also divided or joined some of the lines together, so there are some differences with /t, /n, /r too.Gastrolith
I usually use git diff -w which ignores more whitespace (potentially too much but rarely). Also gitk --all & and check the ignore space change box.Brolly

© 2022 - 2024 — McMap. All rights reserved.