Home > database >  how to view only modified text using git diff between two branches
how to view only modified text using git diff between two branches

Time:12-01

I have a text file in main branch and also in my feature branch. I am editing the text file in feature branch and now want to see the difference between main branch and feature branch.

I am using the following command to see the difference

git diff main..feature input.txt

diff --git a/input.txt b/input.txt
index 3604999..98e6387 100644
--- a/input.txt
    b/input.txt
@@ -1,2  1,4 @@
 # Lord of the rings

 bilbo baggins
 

Now i want to see only bilbo baggins but the code i am running shows the whole difference. How can i show only the newly added lines in the console?

CodePudding user response:

You can use the following command:

git diff --color=always master..feature input.txt | perl -wlne 'print $1 if /^\e\[32m\ \e\[m\e\[32m(.*)\e\[m$/'

I found it here and then adapted it for branches.

  • Related