3

Let's say you have a code that looks like this (XML based notation):

<Root>
    <childA />
        <childB />
            <childC />
</Root>

For a legitimate reason, I need to wrap <Root>...</Root> with another tag so the new code looks like this:

<NewRoot>
    <Root>
        <childA />
            <childB />
                <childC />
    </Root>
</NewRoot>

When I do that obviously git shows every line changed as new indent was introduced. My question is the following, is there any technique or strategy to avoid having all lines shown as being changed?

To clarify, my question revolves around committing initially, I am aware that there are ways of addressing this issue post commit such as using URL parameter for BitBucket or GitHub or doing something like this or this. The reason I am looking for a more robust solution compared to workarounds outlined earlier is the following:

  • using URL parameter is implementation dependent and not portable
  • using git diff (as in CLI) introduces complex non-universal commands and won't apply for git GUI clients
  • avoiding whitespace altogether (as-in writing flat list of XML tags) severely impairs readability of the code afterwards (especially, if it contains a mix of child and adjacent tags)
  • writing new root tag on the same line as old root tag is also not ideal as it doesn't allow to skim the code fast as it gives an impression of two adjacent tags instead of one root tag
Alexander Kucheryuk
  • 606
  • 1
  • 8
  • 16
  • I am not sure about what your question is.. is it about git diff? Or git add? You want to create a commit without space changes? – Francesco Aug 19 '17 at 07:19

0 Answers0