Unstage all deleted files in Git

后端 未结 4 1993
情话喂你
情话喂你 2021-02-09 06:14

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

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

相关标签:
4条回答
  • 2021-02-09 06:22

    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
    
    0 讨论(0)
  • 2021-02-09 06:28

    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 ", "") }
    
    0 讨论(0)
  • 2021-02-09 06:37

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

    0 讨论(0)
  • 2021-02-09 06:46

    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
    
    0 讨论(0)
提交回复
热议问题