Git - print local changes in specific file (print changed lines)

5 points
Created by:

In this short article, we would like to show how to print changes for the indicated file only in Git.

Quick solution:

git diff path/to/changed/file

Hint: use git status to see changed paths under command line.


Practical example

Let's suppose we have updated our project getting the following report using git status:

On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   common/
        modified:   ui/package-lock.json

Untracked files:
  (use "git add <file>..." to include in what will be committed)


no changes added to commit (use "git add" and/or "git commit -a")

Let's suppose we want to check changes in ui/package-lock.json file:

$ git diff ui/package-lock.json

Example output:

Git diff result on a specific file.
Git diff result on a specific file.

As we can see there are only some changes related to dependencies update. 

Alternative titles

  1. Git - diff on specific file
  2. Git - diff on indicated file
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂