Checkout multiple files which have been moved in the working tree

I've moved files from Project to Project/src . Git is under the impression that I've deleted the files from Project and created new files in Project/src .

In addition, I have multiple other changes in the working tree, which I wish to commit. My 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.

I'd like to unstage the source files - *.{cpp,h} . I know how to unstage (the link here, for example, is helpful). What I'd like to avoid doing is typing lots of git checkout <filename> .

I don't want to checkout HEAD , because some of the changes in the working tree I'd like to keep. I've tried doing git checkout *.{cpp,h} , which gives the following:


$ git checkout *.{cpp,h}
zsh: no matches found: *.cpp

Because the files don't currently exist in the working tree, I can't check them out because *.{cpp,h} doesn't match any files.

The files are all in Project/src ; there is probably a regex or something I could run with the output of ls src piped into the git checkout command, but I'd like to know if git can do this for me by itself. Is there a way I can do this in git?


退出*

$ git checkout *.{cpp,h}

For checking out multiple files. I just implemented the wildcards, and it worked well for me. For specific files, we'd probably require a different trick.

I used:

git checkout -- *.*

in my Git Bash. and all the modified files in my workspace were replaced with the ones in the repo.

I hope it helps, thanks.

链接地址: http://www.djcxy.com/p/6172.html

上一篇: `git reset HEAD file`也检出文件吗?

下一篇: 检出已在工作树中移动的多个文件