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 the Working Directory and Staging Area
- Scenario 2: List New, Modified, and Deleted Files of the Git Repository
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:
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:
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:
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:
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.