Unstage all deleted files in Git

跟風遠走 提交于 2019-12-04 11:54:09

问题


I want to unstage all file deletes. Is there an easy way?

I want to apply this to the file pattern of all deletes.


回答1:


The output of git status --porcelain is a great way to build one-liners and scripts for tasks like this:

git status --porcelain | awk '$1 == "D" {print $2}' | xargs git reset HEAD



回答2:


In case your path-/filenames returned from git status contain space characters, the call to awk can be modified to include the entire (quoted) path/filename including spaces:

git status --porcelain|awk '$1 == "D" {print substr($0, index($0,$2))}'|xargs git reset HEAD



回答3:


Just in case anyone else uses git with PowerShell, here is a powershell version of @jefromi's excellent answer:

git status --porcelain | where { $_.StartsWith(" D") } | foreach-object { git reset HEAD $_.replace(" D ", "") }



回答4:


See the section 'Unstaging a staged file' in this book.



来源:https://stackoverflow.com/questions/4249696/unstage-all-deleted-files-in-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!