删除/删除行后如何查找提交? [英] How to find commit when line was deleted/removed?

查看:56
本文介绍了删除/删除行后如何查找提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Git存储库中的文件中有一条已删除的行.我知道一些丢失的文本以及它所在的文件,所以我使用了 git log -S'missingtext'/path/to/file .

I have a deleted line in a file in my Git repository. I knew some of the missing text, and the file that it was in, so I used git log -S'missingtext' /path/to/file.

但是,唯一回来的是提交,其中我添加了包含缺少文本的行.文本不在HEAD中,添加的提交也存在于我的分支中,因此我知道分支历史中的某个提交必须删除了它,但没有显示出来.

However, the only thing that came back was the commit in which I added the line containing the missing text. The text wasn't present in HEAD, and the commit that added it was present in my branch, so I knew that one of the commits in my branch's history must have removed it, but it wasn't showing up.

经过一些手动搜索,结果发现该行在解决合并冲突时被意外删除.所以我想知道:

After some manual searching, it turned out that the line was removed accidentally while resolving a conflict for a merge. So I'm wondering:

  1. 这是镐无法找到删除该行的提交的原因吗?
  2. 我怎么能找到"missingtext"在哪里?被删除而没有手动浏览历史记录?

任何对#1的见识都是很棒的(我认为 git log -S 会给我答案),但是我真正的问题是#2,因为我希望能够避免将来会这样.

Any insight on #1 would be great (I assumed that git log -S would give me my answer), but my real question is #2 since I'd like to be able to avoid this in the future.

推荐答案

git log -c -S'missingtext'/path/to/file

git log 在默认情况下不显示合并提交的差异.尝试使用 -c -cc 标志.

git log doesn't show a diff for merge commits by default. Try the -c or --cc flags.

更多讨论/解释:
https://git-scm.com/docs/git-log
nabble.com

来自git-log文档:

From the git-log docs:

-c 使用此选项,合并提交的差异输出显示每个父项与合并结果之间的差异同时显示父级和父级之间的成对差异结果一次.此外,它仅列出了从所有父母那里修改.

-c With this option, diff output for a merge commit shows the differences from each of the parents to the merge result simultaneously instead of showing pairwise diff between a parent and the result one at a time. Furthermore, it lists only files which were modified from all parents.

-cc 该标志隐含-c选项,并通过省略内容中不感兴趣的块来进一步压缩补丁输出.父母只有两个变体,合并结果会选择其中之一无需修改.

--cc This flag implies the -c option and further compresses the patch output by omitting uninteresting hunks whose contents in the parents have only two variants and the merge result picks one of them without modification.

这篇关于删除/删除行后如何查找提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆