• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

git diff: Show changes to tracked files

by admin

The “git diff” command in Git is used to show the differences or changes between the current state of your repository and the previous commit, or between different branches, commits, or revisions. It primarily focuses on tracking changes made to the files that are already being tracked by Git.

When you run the “git diff” command without any additional arguments, it compares the changes between your working directory (the files you have made modifications to) and the staging area (the files that have been added using “git add”). It shows the differences in a unified diff format, indicating the lines that have been added, modified, or deleted.

You can also use “git diff” with various options and arguments to compare different versions of files or different branches. For example, you can compare the changes between two commits, two branches, or a specific file across different commits.

The “git diff” command is a versatile tool that helps you visualize the differences in your codebase, making it easier to review changes, identify issues, and understand the impact of modifications. It provides valuable insights into the modifications made to your files, allowing you to track and manage the progress of your development work.

By using “git diff,” you can effectively analyze the changes in your code, collaborate with others, and make informed decisions before committing your changes. It is an essential command in Git for understanding the evolution of your repository and maintaining the integrity of your codebase.

git diff Command Examples

1. Show unstaged, uncommitted changes:

# git diff

2. Show all uncommitted changes (including staged ones):

# git diff HEAD

3. Show only staged (added, but not yet committed) changes:

# git diff --staged

4. Show changes from all commits since a given date/time (a date expression, e.g. “1 week 2 days” or an ISO date):

# git diff 'HEAD@[3 months|weeks|days|hours|seconds ago]'

5. Show only names of changed files since a given commit:

# git diff --name-only commit

6. Output a summary of file creations, renames and mode changes since a given commit:

# git diff --summary commit

7. Compare a single file between two branches or commits:

# git diff branch_1..branch_2 [--] /path/to/file

8. Compare different files from the current branch to other branch:

# git diff branch:/path/to/file2 /path/to/file

Filed Under: Linux

Some more articles you might also be interested in …

  1. treetime Command Examples in Linux
  2. chronyc : command not found
  3. How to uninstall local-apt-repository software package in Ubuntu
  4. dolphin Command Examples in Linux
  5. head Command Examples in Linux
  6. ping: command not found
  7. Understanding The /etc/sysconfig Directory
  8. groupadd Command Examples in Linux
  9. Beginners guide to vi editor (command line reference)
  10. acpi Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright