0

Suppose I have a folder data/ with some txt files I want to monitor for changes. I want to run a script and find out what has changed since last commit.

Here is the workflow I have in mind:

  1. Make changes: add, modify or remove files

  2. Stage all the files git add data/

  3. List all the changes git diff --name-only --staged

This should account for three cases:

  1. New file added should be listed
  2. Modified files should be listed.
  3. Deleted files should not be listed.

I need a command to specifically tell me which file since last commited was deleted. So that I can do some stuff in my script before doing a git rm deleted_file.txt

2 Answers 2

1

Your can use --diff-filter to list deleted files only including renaming files. But I think your git diff will also include the deleted files.

git diff --name-only --staged --diff-filter=D 

--diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]

Select only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B). Any combination of the filter characters (including none) can be used. When * (All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing is selected.

Sign up to request clarification or add additional context in comments.

Comments

1

You could use the repository gitk Link.It displays changes in a repo or a selected set of commits.

It supports a few options applicable to the git diff-* commands to control how the changes each commit introduces are shown.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.