git 检出已在工作树中移动的多个文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9345856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Checkout multiple files which have been moved in the working tree
提问by simont
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
.
我已将文件从Project
到Project/src
. Git是的印象是,我已经从删除的文件Project
,并创建新文件Project/src
。
In addition, I have multiple other changes in the working tree, which I wish to commit. My git status
:
此外,我在工作树中有多个其他更改,我希望提交。我的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 avoiddoing is typing lots of git checkout <filename>
.
我想取消暂存源文件 - *.{cpp,h}
. 我知道如何取消暂存(例如,这里的链接很有帮助)。我想避免做的是输入很多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:
我不想结帐HEAD
,因为我想保留工作树中的一些更改。我试过做git checkout *.{cpp,h}
,它给出了以下内容:
$ 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.
因为这些文件当前不存在于工作树中,所以我无法检查它们,因为*.{cpp,h}
不匹配任何文件。
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?
文件都在Project/src
; 可能有一个正则表达式或我可以通过ls src
管道输入git checkout
命令的输出运行的东西,但我想知道 git 是否可以自己为我做这件事。有没有办法在 git 中做到这一点?
回答by Irfy
Escape the *
:
逃脱*
:
$ git checkout \*.{cpp,h}
回答by Divesh
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 -- *.*
git checkout -- *.*
in my Git Bash. and all the modified files in my workspace were replaced with the ones in the repo.
在我的 Git Bash 中。并且我工作区中所有修改过的文件都替换为 repo 中的文件。
I hope it helps, thanks.
我希望它有帮助,谢谢。