diff命令'diff -b'和'git diff'之间的区别 [英] Difference between the diff command 'diff -b' and 'git diff'

查看:691
本文介绍了diff命令'diff -b'和'git diff'之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理 git repo 时,我总是使用 diff -b 来创建补丁。


  1. 这两者之间的区别是什么,也是内部的 git diff / git format-patch 使用linux / unix diff 命令? (我知道 git diff / git format-patch 之间的区别)

  2. 另外,如何修补 patch -p1 不同于 git apply 。我可以应用由 diff 命令( diff -b )生成的补丁并使用 git diff

  3. 处理<$时使用 git diff / apply C $ C> GIT中?我一直在使用 diff / patch ,并且从来没有遇到过任何问题。

请纠正我,如果我的知识上面提到的东西是不够的。

解决方案

b $ b


  1. Git有其自己的内置差异,但两者的输出非常相似,只要有正确的选项。使用内置的diff和 git diff 前端可以获得很多自动化,并且输出始终是 git apply code>或 git am 会喜欢。简而言之,它只是更方便

  2. 我已经完成了这样的事情(fed git diff 输出到补丁,或者普通 diff 输出到 git apply )。它的工作原理,虽然偶尔我不得不编辑的东西在这里和那里得到它的工作,这是一个痛苦。如果我想要 git apply ,或者只是获得 git diff 或者 git am 一个补丁。一般情况下最大的可观察的区别在于, git apply 默认不会部分应用:您必须添加 - reject 使其表现得像补丁的默认。 (另外,所有这些 .orig 文件...) 是的,因为方便。当你进一步了解并使用 git format-patch git am 时,可以批量应用整个系列维护提交信息,包括作者信息等,并自动提交所有内容。


I have always used diff -b to make patches even when working on a git repo.

  1. What is the difference between the two, does git diff / git format-patch also internally makes use of the linux/unix diff command? (I know the difference between git diff/git format-patch)
  2. Also, how is patching with patch -p1 different from git apply. Can i apply a patch generated by the diff command (diff -b) and apply using git diff ?
  3. Is it a good practice to use git diff/apply when working with git? I have been using diff/patch and never faced any problem.

Please correct me if my knowledge of things mentioned above is not adequate.

解决方案

In order:

  1. Git has its own built-in diff but the outputs of both are quite similar, given the right options. Using the built-in diff and the git diff front-end gets you a whole lot of automation, plus the output is always something git apply or git am will like. In short, it's just a lot more convenient.

  2. I've done this sort of thing (fed git diff output to patch, or plain diff output to git apply). It works, although occasionally I have had to edit things here and there to get it to work, which is a pain. It's much more convenient to just get a git diff if I want to git apply or git am a patch. The biggest observable difference in general is that git apply does not do partial apply by default: you must add --reject to make it act like patch's default. (Also, all those .orig files...)

  3. Yes, because of said convenience. When you go a bit further and use git format-patch and git am, you can mass-apply a whole series of patches, maintaining commit messages including authorship information and so on, and getting everything committed automatically.

这篇关于diff命令'diff -b'和'git diff'之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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