列出一个单词消失的文件

发布于 2025-01-23 04:19:09 字数 958 浏览 2 评论 0原文

因此,假设我有两个分支old_release(包含旧版本)和new_release(包含新版本)。在旧版本中,有一个称为cook的工具,我认为它仍在新版本中,但已更名。我需要弄清楚它的重命名。

我想要一个必须满足标准的文件列表;

  1. 文件都存在于old_releasenew_release中。
  2. 字符串cookold_release的版本中找到。
  3. 字符串cook在版本中从new_release中找不到。我需要此条件,因为大多数代码未更新,并且将包含对cook的已停产引用。
  4. 我的存储库很大,检查一个分支需要很长时间。我想要一个避免这种情况的解决方案。

我目前的解决方案看起来像;

git checkout old_release
grep cook . -R -l -I > old_release_cooks.txt
sort -o old_release_cooks_sorted.txt old_release_cooks.txt
git checkout new_release
grep cook . -R -l -I > new_release_cooks.txt
sort -o new_release_cooks_sorted.txt new_release_cooks.txt
vim -d old_release_cooks_sorted.txt new_release_cooks_sorted.txt

除了第4点以外,这还满足我的所有要求。它要求我至少进行一次结帐。严格来说,我想它不会创建不同的文件列表,但是差异足够接近。

有没有办法在不签出的情况下获取此列表?

So, say I have two branches old_release (containing an old release) and new_release (containing a new release). In the old release there was a tool called cook, I think it's still in the new release, but it's been renamed. I need to work out what it's been renamed to.

I would like a list of files which must satisfy the criteria;

  1. File exists in both old_release and new_release.
  2. String cook is found in the version from old_release.
  3. String cook is not found in the version from new_release. I need this condition because most of the code is not updated and will contain defunct references to cook.
  4. My repository is big, and checking out a branch takes a long time. I'd like a solution that avoids that.

My current solution looks like;

git checkout old_release
grep cook . -R -l -I > old_release_cooks.txt
sort -o old_release_cooks_sorted.txt old_release_cooks.txt
git checkout new_release
grep cook . -R -l -I > new_release_cooks.txt
sort -o new_release_cooks_sorted.txt new_release_cooks.txt
vim -d old_release_cooks_sorted.txt new_release_cooks_sorted.txt

This meets all my requirements apart from point 4. It requires I do at least one checkout. Strictly I guess it doesn't create a list of files that differ, but the diff is close enough.

Is there a way to get this list without checking out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苯莒 2025-01-30 04:19:09

使用git grep中的bash中的无用单线检查,并使用comm

word ='cook'rel1 ='old_release'rel2 ='new_release 评估其结果'; COMM -1 -1 -2<(git grep -l'\ b'“ $ word”'\ b'“ $ rel1” | sed's/^[^:]*://'| sort;)<( $ rel2” | sed's/^[^:]*://'|

git grep -l'\ b'“ $ word”'\ b' “ 条件1。满足(两者中必须存在文件)

edit2:简化的表达式

Checkout-free one-liner in bash that uses git grep and evaluates its results using comm:

word='cook' rel1='old_release' rel2='new_release'; comm -1 -2 <(git grep -l '\b'"$word"'\b' "$rel1" | sed 's/^[^:]*://' | sort;) <(git grep -L '\b'"$word"'\b' "$rel2" | sed 's/^[^:]*://' | sort;)

EDIT: adjustments so that also your condition 1. is satisfied (file must exist in both)

EDIT2: simplified expression

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文