列出一个单词消失的文件
因此,假设我有两个分支old_release
(包含旧版本)和new_release
(包含新版本)。在旧版本中,有一个称为cook
的工具,我认为它仍在新版本中,但已更名。我需要弄清楚它的重命名。
我想要一个必须满足标准的文件列表;
- 文件都存在于
old_release
和new_release
中。 - 字符串
cook
在old_release
的版本中找到。 - 字符串
cook
在版本中从new_release
中找不到。我需要此条件,因为大多数代码未更新,并且将包含对cook
的已停产引用。 - 我的存储库很大,检查一个分支需要很长时间。我想要一个避免这种情况的解决方案。
我目前的解决方案看起来像;
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;
- File exists in both
old_release
andnew_release
. - String
cook
is found in the version fromold_release
. - String
cook
is not found in the version fromnew_release
. I need this condition because most of the code is not updated and will contain defunct references tocook
. - 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
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 usingcomm
: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