Languages
[Edit]
EN

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

5 points
Created by:
Root-ssh
116210

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/config.sh
        modified:   run-application.sh
        modified:   ui/package-lock.json

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

        libs/

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. 

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.

❤️💻 🙂

Join