0

I want to calculate this in bash file

files : {
          {
             file {
                     name: "Bla,java"
                     line_changes : [45,146,14]
                  }
          } 
          {
             file {
                     name: "Foo.java"
                     line_changed : [7,8,9,10]
                  }
          }
       }

so I have this

gitOutput=$(git diff origin/master..origin/mybranch)
echo $gitOuput

My problem is :

The output is sooo, not formatted.

Everything is in one line

I cannot parse it logically...

Like Split by \n or split by "diff --git" etc

Also there are no new line . So if there are some, it doesnot make sense.

So I want to know, is there any pretty format option for git diff

[UPDATE]

I have tried this weird approach

git diff origin/master..origin/mybranch > data.txt
data=$(cat data.txt)

Output is : The data.txt is absolutely perfect but the data var. is all messed up...

is it something related to IFS ???

0

1 Answer 1

2

The short answer is: you should add quotes:

gitOutput="$(git diff origin/master..origin/mybranch)"
echo "$gitOuput"

so that line returns are kept as is. This is usually what you want to do in a general matter when having variables in shell.

For a detailed explanation on the use of quotes, see https://unix.stackexchange.com/questions/68694/when-is-double-quoting-necessary

Sign up to request clarification or add additional context in comments.

2 Comments

This is perfect. Can you explain a bit how this "" makes a difference ?
@AkhilSoni The link in the answer explains it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.