git diff文件反对它的最后更改 [英] git diff file against its last change

查看:142
本文介绍了git diff文件反对它的最后更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能让git在特定文件之间产生差异,因为它现在存在,并且在最后一次提交改变它之前存在?

是,如果我们知道:

  $ git log --oneline myfile 
123abc修复一些内容
456def fobble the foos
789dba初始提交

然后 git diff 456def myfile 显示myfile的最后更改。如果没有 git log 产生的知识,可以做同样的事情。 123abc中改变了什么?

解决方案

这确实存在,但它实际上是 git log

  git log -p [--follow] [-1]< path> 

请注意,也可以使用 -p 以显示单个提交的内联差异:

  git log -p -1< commit> 

使用的选项:


  • -p (还有 -u - patch )隐藏在 git-log 手册页中的deeeeeeeep中,实际上是 git-diff 。当与 log 一起使用时,它会显示为每个提交生成的修补程序以及提交信息和隐藏的 em>提交,它不会触及指定的< path> 。 (这个行为在 - full-diff 段落中描述,这会导致显示每个提交的完全差异。)

  • -1 仅显示对指定文件的最近更改 -n 1 可以用来代替 -1 );否则,显示该文件的所有非零差异。
  • 需要
  • - follow 查看重命名之前发生的更改。



据我所知,这是立即看到最后一组的唯一方法在不使用 git log (或类似的)的情况下对文件所做的更改,可以计算介入版本的数量,也可以确定提交的散列。



要查看较早的修订版更改,只需滚动浏览日志,或者指定从中启动日志的提交或标记。 (当然,指定一个提交或标签会让你回到原始问题,找出正确的提交或标签是什么。)



信用到期的信用:

p>


  • 我发现 log -p 感谢回答此问题
  • >这个答案,让我看看 - 遵循选项。
  • 感谢ChrisBetti提及 -n 1 选项和atatko提及 -1 变体。

  • 存入sweaver2112让我实际阅读文档并找出 -p 意味着语义。


Is it possible to get git to produce a diff between a specific file as it exists now, and as it existed before the last commit that changed it?

That is, if we know:

$ git log --oneline myfile
123abc Fix some stuff
456def Frobble the foos
789dba Initial commit

Then git diff 456def myfile shows the last change to myfile. Is is possible to do the same without the knowledge produced by the git log; what changed in 123abc?

解决方案

This does exist, but it's actually a feature of git log:

git log -p [--follow] [-1] <path>

Note that -p can also be used to show the inline diff from a single commit:

git log -p -1 <commit>

Options used:

  • -p (also -u or --patch) is hidden deeeeeeeep in the git-log man page, and is actually a display option for git-diff. When used with log, it shows the patch that would be generated for each commit, along with the commit information—and hides commits that do not touch the specified <path>. (This behavior is described in the paragraph on --full-diff, which causes the full diff of each commit to be shown.)
  • -1 shows just the most recent change to the specified file (-n 1 can be used instead of -1); otherwise, all non-zero diffs of that file are shown.
  • --follow is required to see changes that occurred prior to a rename.

As far as I can tell, this is the only way to immediately see the last set of changes made to a file without using git log (or similar) to either count the number of intervening revisions or determine the hash of the commit.

To see older revisions changes, just scroll through the log, or specify a commit or tag from which to start the log. (Of course, specifying a commit or tag returns you to the original problem of figuring out what the correct commit or tag is.)

Credit where credit is due:

  • I discovered log -p thanks to this answer.
  • Credit to FranciscoPuga and this answer for showing me the --follow option.
  • Credit to ChrisBetti for mentioning the -n 1 option and atatko for mentioning the -1 variant.
  • Credit to sweaver2112 for getting me to actually read the documentation and figure out what -p "means" semantically.

这篇关于git diff文件反对它的最后更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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