[英]Git Checkout Using Pathspec with Wildcard
I would like to restore some files in the working directory to the state of the latest commit on the current local branch, which is master
, however, my attempts to use git checkout to achieve this have failed consistently.我想将工作目录中的一些文件恢复到当前本地分支上最新提交的状态,即master
,但是,我尝试使用 git checkout 来实现这一点一直失败。
I have confirmed that the following works: git checkout HEAD src/graphql/User.ts
我已经确认以下有效: git checkout HEAD src/graphql/User.ts
But I know that I should be able to use a wildcard in the pathspec, ie : git checkout HEAD '*/User.ts'
但我知道我应该能够在路径规范中使用通配符,即: git checkout HEAD '*/User.ts'
However this fails.然而这失败了。
How can I use a pathspec with a wildcard to restore a limited set of files to the state stored in the latest or previous commit?如何使用带有通配符的路径规范将一组有限的文件恢复到存储在最新或先前提交中的状态?
As it turns out, there are two solutions to this problem.事实证明,这个问题有两种解决方案。
1. Git has shipped a new feature calledrestore
which allows for the use of a pathspec.
1. Git 提供了一个名为restore
的新功能,它允许使用路径规范。
See ( https://git-scm.com/docs/git-restore ).
请参阅( https://git-scm.com/docs/git-restore )。
So
所以
git restore */User.ts
will work.将工作。
2. The following will work as well, although I'm not quite sure why: 2.以下也可以工作,虽然我不太确定为什么:
git checkout -- '*/User.ts'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.