Git使用* filename来指定文件(Git use *filename to specify file)

编程入门 行业动态 更新时间:2024-10-27 16:35:02
Git使用* filename来指定文件(Git use *filename to specify file)

在这个问题中 ,答案说我可以用*来指向文件。

这适用于git add ,但是当我尝试将它与git checkout <commit> <file>我遇到了一个问题。

第二个答案中提到的git add **/DSManger.java方法也不适用于git checkout 。

leafpile (notification *+) Dev $ git add *NewTaskActivity.java (no problem) leafpile (notification *+) Dev $ git checkout dbd1 *NewTaskActivity.java error: pathspec '*NewTaskActivity.java' did not match any file(s) known to git.

为什么?

In this question, the answer said that I can use *to point to files.

This works with git add, but when I try to use this with git checkout <commit> <file> I run into a problem.

The git add **/DSManger.java method mentioned in the second answer doesn't work with git checkout either.

leafpile (notification *+) Dev $ git add *NewTaskActivity.java (no problem) leafpile (notification *+) Dev $ git checkout dbd1 *NewTaskActivity.java error: pathspec '*NewTaskActivity.java' did not match any file(s) known to git.

Why?

最满意答案

当你做一个git时,它会递归地添加你提出的内容(可以像你一样使用regexp)。

但是当你结账时,你需要提供完整的路径

您需要将完整路径传递给结帐

# This is the syntax git checkout <commit> <file> # pass the full path to checkout git checkout <commit> /path/to/file/NewTaskActivity.java # checkout all files under the given folder: git checkout <commit id> -- path/to/folder/**

Checking out file from different branch

# when checking out from branch you need to add the -- before the file path git checkout <branch> -- <path to file>

When you do a git add it's adding recursively the content you asked (can be regexp as you did).

But when you checkout you need to supply the full path

You need to pass the full path to the checkout

# This is the syntax git checkout <commit> <file> # pass the full path to checkout git checkout <commit> /path/to/file/NewTaskActivity.java # checkout all files under the given folder: git checkout <commit id> -- path/to/folder/**

Checking out file from different branch

# when checking out from branch you need to add the -- before the file path git checkout <branch> -- <path to file>

更多推荐

本文发布于:2023-08-07 16:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465492.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   Git   filename   file

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!