Skip to content

Instantly share code, notes, and snippets.

@IllIllI000
Last active March 11, 2026 17:58
Show Gist options
  • Select an option

  • Save IllIllI000/21deaa6a55c95a6ec9ca893009ee494f to your computer and use it in GitHub Desktop.

Select an option

Save IllIllI000/21deaa6a55c95a6ec9ca893009ee494f to your computer and use it in GitHub Desktop.

The original file:

$ cat DiffTest.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract DiffTest {
    function test() external pure returns (string memory) {
        return "Hello World!";
    }
}

Back up the original before making changes:

$ cp DiffTest.sol DiffTest.sol.orig

Alter the file:

$ sed -i 's/World/C4/g' DiffTest.sol 

$ cat DiffTest.sol 
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract DiffTest {
    function test() external pure returns (string memory) {
        return "Hello C4!";
    }
}

View the diff:

$ git diff --no-index DiffTest.sol.orig DiffTest.sol
diff --git a/DiffTest.sol.orig b/DiffTest.sol
index 6d613dd..b7afd47 100644
--- a/DiffTest.sol.orig
+++ b/DiffTest.sol
@@ -3,6 +3,6 @@ pragma solidity ^0.8.0;
 
 contract DiffTest {
     function test() external pure returns (string memory) {
-        return "Hello World!";
+        return "Hello C4!";
     }
 }

Create markdown of the diff:

$ echo "\`\`\`diff" > diff.md
$ git diff --no-index DiffTest.sol.orig DiffTest.sol >> diff.md
$ echo "\`\`\`" >> diff.md

Result:

$ cat diff.md
```diff
diff --git a/DiffTest.sol.orig b/DiffTest.sol
index 6d613dd..b7afd47 100644
--- a/DiffTest.sol.orig
+++ b/DiffTest.sol
@@ -3,6 +3,6 @@ pragma solidity ^0.8.0;
 
 contract DiffTest {
     function test() external pure returns (string memory) {
-        return "Hello World!";
+        return "Hello C4!";
     }
 }
```

Displayed result:

diff --git a/DiffTest.sol.orig b/DiffTest.sol
index 6d613dd..b7afd47 100644
--- a/DiffTest.sol.orig
+++ b/DiffTest.sol
@@ -3,6 +3,6 @@ pragma solidity ^0.8.0;
 
 contract DiffTest {
     function test() external pure returns (string memory) {
-        return "Hello World!";
+        return "Hello C4!";
     }
 }

If changes are made to multiple files in a cloned git repository, one can run the following:

$ git diff > /tmp/changes.patch

and later re-apply all of the changes from all of the files using:

$ git apply /tmp/changes.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment