Git

Git List of New/Modified/Deleted Files

Git is a famous tool that is utilized to track the modifications in files. The Git repository contains several new, deleted, and modified files. When a user creates a new file, modifies it, or deletes it, these changes need to be added to the Git index for tracking purposes. Moreover, Git commands are available to list new, modified, and deleted files.

This article will demonstrate different scenarios for listing new, modified, and deleted files in Git.

How to List New, Deleted, and Modified Files in Git?

There can be different scenarios for this situation, such as:

Scenario 1: List New, Modified, and Deleted Files of Working Directory and Staging Area

The working directory contains the untracked files while the staging area contains all the tracked files. Tracked files are the files that are added to the Git staging area (index) and untracked files are the files that have not been added to the Git index yet.

To view all the new, modified, and deleted files of the working directory and staging area, utilize the “git status” command:

git status

The below output shows all the tracked and untracked files and modifications. Here:

  • newFile.txt” is the newly added tracked file in the staging area.
  • File1.txt” is the modified untracked file in the working directory.
  • feat.txt” is the deleted untracked file in the working directory.
  • index.txt” is the newly added untracked file in the working directory:

Moreover, the “–porcelain” option can also be utilized with the “git status” command to display the status of the working directory and staging area in a concise format:

git status --porcelain

In the below output:

  • M” represents the modified file in the working directory.
  • D” shows the deleted file in the working directory.
  • A” indicates a new file added to the staging index.
  • ??” displays the untracked file:

Alternatively, the following command can also be used to get the same output:

git ls-files -o && git checkout

Here:

  • git ls-files -o” is used to list new files
  • git checkout” command is used for added, modified, and deleted files:

Scenario 2: List New, Modified, and Deleted Files of Git Repository

The Git repository contains all the files and modifications that have been committed. To list the new, modified, and deleted files of the Git repository, utilize the provided command:

git whatchanged --oneline

In the below screenshot,

  • D” shows the deleted files from the Git repository.
  • M” indicates the modified committed files.
  • A” represents the newly added files in the Git repository:

That was all about listing the new, modified, and deleted files in Git.

Conclusion

To list all the new, modified, and deleted files of the working directory and staging area, the “git status” or “git ls-files -o && git checkout” commands can be used. Moreover, the “–porcelain” option can also be utilized with the “git status” command to display output in a concise format. In order to list the new, modified, and deleted files of the Git repository, use the “git whatchanged –oneline” command. This article demonstrated different scenarios for listing new, modified, and deleted files in Git.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.