Home > front end >  How to get the terminal result into a file with full file name in linux
How to get the terminal result into a file with full file name in linux

Time:12-23

I'm trying to write how many lines of code difference are there between 2 git branches. So i ran the git command for the difference, on terminal, where it output the file location along with the number of different lines between two branches.

Although, i know the command to write the terminal output into a file. I've used the below mentioned command to write the terminal output into a file 'code_mismatch.txt':

git diff --compact-summary --ignore-space-change remotes/dev_admin/master origin/master &> code_mismatch.txt

A glance on the code_mismatch.txt file:

 application/models/admin/Template_model.php        |    97  -
 application/models/admin/Ticket_model.php          |    75  -
 .../models/admin/Tickets_v2/Channel_model.php      |    10  -
 .../models/admin/Tickets_v2/Superadminmodel.php    |    30  -
 .../models/admin/Tickets_v2/Template_model.php     |    26  -
 .../models/admin/Tickets_v2/Ticket_model.php       |     4  -
 .../merchant/dashboard/ticket_destinations.php     |    16  -
 .../ticket_list.php (gone)                         |    94 -
 application/views/activity_overview.php            |     2  -
 application/views/admin/channel.php                |    15  -
 .../views/admin/company/companysettings_v1.php     |    57  -

But the problem i'm facing is, if the file location written inside the 'code_mismatch.txt' file is a bit long, then it replaces the starting part of the file location with dots like this '...'.

If i try to run the same command without writing the output into code_mismatch.txt file then on the terminal i'm getting full location of the file.

git diff --compact-summary --ignore-space-change remotes/dev_admin/master origin/master

A glance on terminal output:

 application/models/admin/Template_model.php                                                    |    97  -
 application/models/admin/Ticket_model.php                                                      |    75  -
 application/models/admin/Tickets_v2/Channel_model.php                                          |    10  -
 application/models/admin/Tickets_v2/Superadminmodel.php                                        |    30  -
 application/models/admin/Tickets_v2/Template_model.php                                         |    26  -
 application/models/admin/Tickets_v2/Ticket_model.php                                           |     4  -
 application/views/V1/codes/merchant/dashboard/ticket_destinations.php                          |    16  -
 application/views/V1/ticket_destinations_list/ticket_list.php (gone)                           |    94 -
 application/views/activity_overview.php                                                        |     2  -
 application/views/admin/channel.php                                                            |    15  -
 application/views/admin/company/companysettings_v1.php                                         |    57  -
 application/views/admin/company/create_new_company.php                                         |   456   -

Is there a way i can write my file same as the terminal output..??

Thanks!

CodePudding user response:

Don't use the convenience commands, the so-called "porcelain", for scripting. Use the core commands, the ones the convenience commands are built on.

git diff-tree --ignore-space-change --numstat remotes/dev_admin/master origin/master

will produce output with all the tradeoffs between readability by computers and humans decided in the computer's favor rather than the other way round.

  • Related