1

Given a git repository with the following file structure:

<repo root>
  foo
    example.md

I have committed example.md with the contents Hello world. If I navigate to the foo directory and make a change to example.md, I can generate a relative diff with git diff --relative > d.diff with the contents:

diff --git a/example.md b/example.md
index 802992c..fb5067b 100644
--- a/example.md
+++ b/example.md
@@ -1 +1 @@
-Hello world
+Hello again

If I now checkout example.md to undo the change, then try to apply the diff with git apply d.diff (still in the foo directory), the command exits silently and no changes are applied. How can I apply this relative diff, or generate a relative diff in such a way that it can be applied?

dysfunction
  • 169
  • 9

1 Answers1

0

This doesn't directly answer the question of why git apply doesn't work here, but based on the answer in https://stackoverflow.com/a/42386570/1340041 I've found a workaround: patch -p1 < d.diff

dysfunction
  • 169
  • 9