签出已在工作树中移动的多个文件

sim*_*ont 12 git

我已将文件Project移至Project/src.Git的印象是我从中删除了文件Project并创建了新文件Project/src.

另外,我在工作树中有多个其他更改,我希望提交.我的git status:


 $ git  status
# On branch feature/cmake
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#   new file:   .gitignore
#   new file:   CMakeLists.txt
#   deleted:    Wasa.xcodeproj/project.pbxproj
#   deleted:    Wasa/Wasa.1
#   renamed:    Wasa/main.cpp -> main.cpp
#   new file:   src/CMakeLists.txt  
#  Lots of new files listed here
#
# Changes not staged for commit:
#   (use "git add/rm ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
#   modified:   CMakeLists.txt
#   deleted:    IODevice.h
#  Lots of deleted files listed here.
Run Code Online (Sandbox Code Playgroud)

我想取消暂存源文件 - *.{cpp,h}.我知道如何取消演出(例如,这里的链接很有帮助).我想要避免做的是打字很多git checkout <filename>.

我不想结账HEAD,因为工作树中的一些变化我想保留.我试过了git checkout *.{cpp,h},它给出了以下内容:


$ git checkout *.{cpp,h}
zsh: no matches found: *.cpp
Run Code Online (Sandbox Code Playgroud)

因为工作树中当前不存在这些文件,所以我无法检查它们,因为它们*.{cpp,h}与任何文件都不匹配.

文件都在Project/src; 可能有一个正则表达式或者我可以用ls src管道输出到git checkout命令运行的东西,但我想知道git是否可以自己为我做这个.有没有办法可以用git做到这一点?

Irf*_*rfy 28

逃离*:

$ git checkout \*.{cpp,h}
Run Code Online (Sandbox Code Playgroud)

  • `$ git checkout\*.{cpp,h}`将检查与存储库*中的shell glob模式`*.{cpp,h}`*匹配的任何文件.如果没有反斜杠,它将匹配(并扩展到)当前目录*中的文件*. (2认同)