Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top