Jaime Rivera
Jaime Rivera

Reputation: 1406

Git Diff, how can I get added lines?

I have some sql files in my project:

The content of one file in the last version is:

line1...
line2...
line3...

The same file in my current commit has:

line1...
line2...
line3...
line4...
line5...

I want a git command to get all the new lines from all ".sql" files.

I was trying with:

git diff HEAD~1 HEAD *.sql

diff --git a/patch.sql b/patch.sql
index e654124..c5692e4 100644
--- a/patch.sql
+++ b/patch.sql
@@ -4,3 +4,7 @@ line2
line1...
line2...
line3...
+line4...
+line5...

That's fine, but i just want:

line4...
line5...

Upvotes: 1

Views: 174

Answers (1)

Christopher
Christopher

Reputation: 44244

You could just pipe it to grep:

git diff HEAD~1 HEAD -- *.sql | grep "^+[a-Z0-9]"

You need to extra regex to avoid matching +++ b/patch.sql

Upvotes: 1

Related Questions