Supun Wijerathne
Supun Wijerathne

Reputation: 12958

How to see the changes happened in a file, resulted by uncommitted changes git?

Suppose I am in someBranch in git and I have made some changes to files file1 and file2 which are not committed yet.

Is there a way/git command to see(cat in linux) the lines I have changed of a given file(ex: file1) in terminal?

Upvotes: 1

Views: 228

Answers (3)

Maksym Semenykhin
Maksym Semenykhin

Reputation: 1945

You probably need look at command

git diff [file]

It will show uncommitted changes to specific file

Here is how you can do it:

git diff path/file1

And live example :

git diff common/models/Transaction.php


diff --git a/common/models/Transaction.php b/common/models/Transaction.php
index d45cccd..5e3ffd4 100644
--- a/common/models/Transaction.php
+++ b/common/models/Transaction.php
@@ -20,7 +20,7 @@ use Yii;
 class Transaction extends \yii\db\ActiveRecord
 {

-    const TYPE_PURCHASE  = 'PURCHASE';
+    const TYPE_PURCHASE  = 'purchase';

     const STATUS_NORMAL = 'NORMAL';
     const STATUS_NEW = 'NEW';

Upvotes: 1

ElpieKay
ElpieKay

Reputation: 30958

If you have just modified the file but not git add yet, git diff or git diff -- file1.

If you have added it but not committed, git diff --cached or git diff --cached -- file1.

Upvotes: 1

Charlie Fish
Charlie Fish

Reputation: 20566

git diff file1

git-diff is probably what you are looking for.

Upvotes: 1

Related Questions