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

后端 未结 8 736
不思量自难忘°
不思量自难忘° 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 16:43

    Since Windows doesn't have a grep command, this worked for me in PowerShell:

    git log --find-renames --diff-filter=D --summary | Select-String -Pattern "delete mode" | sort -u > deletions.txt
    
    0 讨论(0)
  • 2020-11-30 16:49

    Citing this Stack Overflow answer.

    It is a pretty neat way to get type-of-change (A:Added, M:Modified, D:Deleted) for each file that got changed.

    git diff --name-status
    
    0 讨论(0)
  • 2020-11-30 16:50

    Show all deleted files in some_branch

    git diff origin/master...origin/some_branch --name-status | grep ^D
    

    or

    git diff origin/master...origin/some_branch --name-status --diff-filter=D 
    
    0 讨论(0)
  • 2020-11-30 16:55

    If you're only interested in seeing the currently deleted files, you can use this:

    git ls-files --deleted
    

    if you then want to remove them (in case you deleted them not using "git rm") pipe that result to xargs git rm

    git ls-files --deleted | xargs git rm
    
    0 讨论(0)
  • 2020-11-30 17:03
    git log --diff-filter=D --summary
    

    See Find and restore a deleted file in a Git repository

    If you don't want all the information about which commit they were removed in, you can just add a grep delete in there.

    git log --diff-filter=D --summary | grep delete
    
    0 讨论(0)
  • 2020-11-30 17:03

    This does what you want, I think:

    git log --all --pretty=format: --name-only --diff-filter=D | sort -u
    

    ... which I've just taken more-or-less directly from this other answer.

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