Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkout multiple files which have been moved in the working tree

Tags:

git

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?

like image 534
simont Avatar asked Feb 19 '12 01:02

simont


1 Answers

Escape the *:

$ git checkout \*.{cpp,h}
like image 87
Irfy Avatar answered Nov 15 '22 23:11

Irfy