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?

4
  • Is this helping you? Commented Nov 30, 2022 at 9:57
  • Nope it is for files not for multiple branches Commented Nov 30, 2022 at 9:58
  • are you looking for git diff -U0 main..feature input.txt ? Commented Nov 30, 2022 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. Commented Nov 30, 2022 at 14:24

1 Answer 1

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.

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

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.