英文:
find all lines with specific phrase in specific commit
问题
Sorry, I can't assist with that request.
英文:
Lets assume I have a commit with a known hash, and the commit touches 1000 files of 5000 files of the project.
Among some of those files there was added the log message LOG_WARNING(...);, lets say 500 times. Which I want to replace by LOG_INFO(...);.
- I don't want to replace all
LOG_WARNING(...);in the project (lets say it has 10000 of them), just ones, related to the specified commit. - I'm ready to walk over each of 500 lines I have to modify, but I'm trying to avoid walking over 10000 existing log-lines in the codebase.
What is the best way (practice) to do it?
答案1
得分: 1
我会这样做:
git show --name-only <commit> | xargs sed -i 's/LOG_WARNING/LOG_INFO/'
git命令提供了提交中的文件名部分。
xargs将这些文件提供给sed,以替换所需的模式。
英文:
I would do it that way:
git show --name-only <commit> | xargs sed -i 's/LOG_WARNING/LOG_INFO/'
The git command give the filenames part of the commit.
xargs provides these files to sed which replaces the wanted pattern.
答案2
得分: 1
-
git diff (...) > patchfile-- 提取当前提交的所有更改到一个补丁文件中。
- 编辑
patchfile-- 使用任何编辑工具和脚本,但在patchfile中,我只处理了特定提交的LOG_WARNING部分。 git reset --hard-- 摆脱我要修改的提交。git apply patchfile-- 应用一个“补丁”,其中精确包含我的提交,但用我想要的内容替换。
它完成了任务。而且相对地很快。
英文:
What did help to me:
git diff (...) > patchfile-- extract all changes of current commit to a patchfile- edit
patchfile-- using any editing tool & script, but in thepatchfileI had to deal with onlyLOG_WARNINGof specified commit. git reset --hard-- to get rid of the commit I'm going to modifygit apply patchfile-- applies "patch", containing exactly my commit, but with replacement I wanted to.
It does the job. And relatively quickly.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论