How can I list all the deleted files in a Git repository?

后端 未结 8 737
不思量自难忘°
不思量自难忘° 2020-11-30 16:13

I know Git stores information of when files get deleted and I am able to check individual commits to see which files have been removed, but is there a command that would gen

相关标签:
8条回答
  • 2020-11-30 17:03

    This will get you a list of all files that were deleted in all branches, sorted by their path:

    git log --diff-filter=D --summary | grep "delete mode 100" | cut -c 21- | sort > deleted.txt
    

    Works in msysgit (2.6.1.windows.1). Note we need "delete mode 100" as git files may have been commited as mode 100644 or 100755.

    0 讨论(0)
  • 2020-11-30 17:08

    And if you want to somehow constrain the results here's a nice one:

    $ git log --diff-filter=D --summary | sed -n '/^commit/h;/\/some_dir\//{G;s/\ncommit \(.*\)/ \1/gp}'
    delete mode 100644 blah/some_dir/file1 d3bfbbeba5b5c1da73c432cb3fb61990bdcf6f64
    delete mode 100644 blah/some_dir/file2 d3bfbbeba5b5c1da73c432cb3fb61990bdcf6f64
    delete mode 100644 blah/some_dir/file3 9c89b91d8df7c95c6043184154c476623414fcb7
    

    You'll get all files deleted from some_dir (see the sed command) together with the commit number in which it happen. Any sed regex will do (I use this to find deleted file types, etc)

    0 讨论(0)
提交回复
热议问题