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