0

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?

Zykxpython
  • 15
  • 2
  • Is [this](https://stackoverflow.com/questions/25497881/git-diff-is-it-possible-to-show-only-changed-lines) helping you? – Raida Nov 30 '22 at 09:57
  • Nope it is for files not for multiple branches – Zykxpython Nov 30 '22 at 09:58
  • are you looking for `git diff -U0 main..feature input.txt` ? – LeGEC Nov 30 '22 at 10:54
  • Note that the two-dot sequence (`git diff main..feature`) is semi-deprecated at this point; use the two name sequence (`git diff main feature`) to make sure your code works in Git 3000 or whatever version it might eventually be, released in perhaps 2035 or something. :-) These two do exactly the same thing but most people find `git diff main feature` clearer, apparently. – torek Nov 30 '22 at 14:24

1 Answers1

0

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.

Raida
  • 1,206
  • 5
  • 17
  • Did you commit it? If you specify `master..feature` it will do the difference between `master` branch and `feature` branch with commits. If you specify only `master` it will do the difference between `master` branch and your current working directory, so without commits. – Raida Nov 30 '22 at 10:23