Languages
[Edit]
EN

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

5 points
Created by:
Root-ssh
175340

In this short article, we would like to show how to print changes only for the indicated file 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.

 

See also

  1. Git - print changes between specific commits (print changed lines)

Alternative titles

  1. Git - diff on specific file
  2. Git - diff on indicated file
  3. Git - print local changes on specific file (print changed lines)
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.

❤️💻 🙂

Join