Search code examples
gitbashdelete-filegit-log

How to exclude the deleted file in git log command?


I need to exclude the deleted file in git log. I use the command git log -1 --name-only --pretty=format:eee6ce6 to get the changed file name in last that commit. I using pre-receive hook to block the specific file type committing. Above command listed all file which has modified.

But I wanna allow the user to remove the specific file types. How can I do this?

  • I tried this git log -1 --name-only --pretty=format:eee6ce6-filter=d command too, But it also listing the deleted file.
  • This git log -1 --diff-filter=d --name-only perfectly works. But the it giving commit ID, author name, date also. I want only the file name.

Solution

  • You can get the names of deleted files in the last commit using git diff:

    git diff --name-only --diff-filter=D HEAD~1