- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我已经在谷歌上搜索了 2 个小时,仍然找不到解决方案。
我想将所有带有通配符的文件 check out 到特定修订版。我使用了以下命令:
git checkout 663090b1c 'src/app/**/*.spec.ts'
但是它说:
error: pathspec 'src/app/**/*.spec.ts' did not match any file(s) known to git.
谁能帮帮我?
最佳答案
我相信这应该可行,但显然行不通。这是在 Documentation/**/*.txt
上使用最新 Git(您可以在 https://github.com/git/git 获得)的效果。
我构建了 Git,然后使用 Git 系统(在 2.21,略低于这个版本 2.22.0.545.g9c9b961d7e
)来执行此操作:
$ rm Documentation/*/*.txt
$ git status --short | head
D Documentation/RelNotes/1.5.0.1.txt
D Documentation/RelNotes/1.5.0.2.txt
D Documentation/RelNotes/1.5.0.3.txt
D Documentation/RelNotes/1.5.0.4.txt
D Documentation/RelNotes/1.5.0.5.txt
D Documentation/RelNotes/1.5.0.6.txt
D Documentation/RelNotes/1.5.0.7.txt
D Documentation/RelNotes/1.5.0.txt
D Documentation/RelNotes/1.5.1.1.txt
D Documentation/RelNotes/1.5.1.2.txt
$ git checkout -- 'Documentation/**/*.txt'
$ git status --short | head
$
然而,现在:
$ ./git checkout HEAD -- 'Documentation/**/*.txt'
error: pathspec 'Documentation/**/*.txt' did not match any file(s) known to git
看起来 pathspecs 在与索引一起使用时有效,但在与提交哈希一起使用时无效。
作为解决方法——请注意,此解决方法有些缺陷,但您可以进一步修补它——您可以首先将所需的提交读入临时索引,然后从临时索引执行 git checkout
指数。以下脚本完全未经测试。
#! /bin/sh
# git-co-c-ps: git checkout <commit> <pathspec>
# work around a bug in which combining <commit> and <pathspec> does not work
. git-sh-setup
case $# in
2) ;;
*) die "usage: $0 <commit> <pathspec>";;
esac
hash=$(git rev-parse "$1^{commit}") || exit 1
export GIT_INDEX_FILE=$(mktemp) || exit 1
rm -f $GIT_INDEX_FILE
trap "rm -f $GIT_INDEX_FILE" 0 1 2 3 15
git read-tree "$hash" || exit 1
git checkout -- "$2"
这里的(未经测试的)想法是将“$1”指定的提交读入临时索引。 (我们可以将 ^{commit}
放宽为 ^{tree}
,因为任何树结构都应该足够了。)然后,将其读入临时索引后,我们使用“git checkout”模式和有效的路径规范($2),使用临时索引。这将写入工作树。
缺陷是现在更新的工作树文件没有在索引中也更新。真正的 git checkout
会将这些相同的文件复制到索引中。应该可以取消设置 $GIT_INDEX_FILE
和 git add
添加的文件到真实索引。这留作练习。请注意,它不像 git add -- "$2"
那样微不足道,因为一些工作树文件可能在工作树中 不 因为它们被读入了git read-tree
操作的临时索引,而是因为它们已经在工作树中。 (有些可能已被跟踪和修改但尚未上演/添加,而其他一些可能未被跟踪。)
另一个可能更好的解决方法是在临时索引上使用 git ls-files
来查找感兴趣的文件。使用 xargs
或类似方法将这些文件名传递给在没有临时索引的情况下运行的 git checkout
:
files_file=$(mktemp)
trap "rm -f $files_file" 0 1 2 3 15
(
export GIT_INDEX_FILE=$(mktemp) || exit 125
rm -f $GIT_INDEX_FILE
trap "rm -f $GIT_INDEX_FILE" 0 1 2 3 15
git read-tree $hash
git ls-files -z -- "$2"
) > $files_file
# if the inner shell exited with an error, exit now
case $? in 125) exit 1;; esac
xargs -0 ...
(填写其余部分以制作可用的 Git shell 命令也留作练习。)
关于使用通配符对特定修订版进行 Git check out ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57193458/
这个问题在这里已经有了答案: What's the proper value for a checked attribute of an HTML checkbox? (10 个答案) 关闭 8 年
我使用这个制作了自定义复选框: enter link description here 也可在 stackoverflow 上获得:enter link description here 但我正在尝试
我需要使用 CSS“checkbox-hack”来实现滑动菜单指示器效果,我唯一的方法是通过 JavaScript 附加输入元素。我被迫通过在线工具 MonoSolutions 执行此操作,并且我受到
此代码运行良好,但缺少一些我需要的东西。基本上,如果输入有一个 checked="checked" 属性,它应该使其他两个元素保持禁用状态。如果未选中,则元素已启用。 这是我在 jsFiddle 上的
当我的人 checkout 文件时,我希望他们将其锁定,以便其他人也无法进行更改,我从这篇文章中看到:http://msdn.microsoft.com/en-us/library/jj155783.
请告诉我这些函数的作用。 最佳答案 这些是基于框架的、与语言无关的方法,用于在 .NET 中定义代码契约。虽然某些语言(如 spec# 和 Delphi Prism)对代码契约具有一流的语言支持,但这
假设以下场景:您有 2 个单选按钮,它们具有相同的名称,并且都被选中(我知道这是无效的): 为什么下面两个选择器的行为不同? $('.input:checked').size(); // retu
我正在尝试收听广播。以下均不起作用: [编辑] $('selector').attr('checked','checked'); $('selector').attr('checked',true);
我实际上在努力理解此类型错误。 任何人都知道我如何更正代码?谢谢 CheckIn checkin1 = new CheckIn(location1, dt); CheckInMonths checkI
我有这段代码,但不起作用。 .on("click","span.name", function selectThisName(e) { if (e.altKey) {
我现在是 Espresso 的新手,我遇到了这个异常: android.support.test.espresso.AmbiguousViewMatcherException: 'with id: a
我已经创建了一个基本的 2 单选按钮表单,如下面的示例所示。 观察浏览器渲染,我们看到元素 1 被选中。我们检查元素 1 和元素 2。 当我点击元素 2 时,我希望元素 1 的 checked=che
我在查找以下 jquery/checkbox 行为的原因时遇到问题。 $( this.obj + ' table.sgrid-content > thead > tr > th > input.sel
以下逻辑应用在上午 10 点触发并运行 SQL Server 查询。从图片中可以看出,结果集是空的。 条件检查检查查询的结果集是否为空。 (第二张图) 这仍然如何转化为 True?结果显然是空的。 最
我想知道哪种操作更快: int c = version1.compareTo(version2); 这个 if (c == 1) 或者这个 if (c > 0) 符号比较是否只使用一位检查,而相等比较
我有一个包含大约 100 个问题的表单,每个问题都有一个单选按钮和一些复选框,因此我需要用户能够保存表单并在以后加载它。我还需要检查用户在此 session 中更改了哪些。 本题解决问题:How ca
我正在编写一个小程序,需要用户决定一些 bool 值。我已经制作了复选框来处理这一部分,但问题是每次我选中或取消选中一个复选框时,所有其他复选框都会跟随。 我在网上搜索过,但我找到的唯一解释( pyt
我有以下代码片段(我使用的是 jQuery 1.4.2): $.post('/Ads/GetAdStatsRow/', { 'ad_id': id }, function(result) {
我的代码发生了一些奇怪的事情。我有两个按钮,其中一个带有 .add 和 .remove 类,有一个复选框会根据按下哪个按钮而打开和关闭,因此如果您使用删除按钮删除,则选中的复选框将被选中,否则复选框将
我陷入了一种情况,我必须通过“选中”工具栏中的复选框来“选中”列表中存在的所有复选框。 这是创建复选框列表的代码:- itemTpl: 'checked="checked" /> {groupName
我是一名优秀的程序员,十分优秀!