I would like to create a .patch file that can remove/delete a file without considering its content.
In my git repo, I have myfile1.txt, its content:
Hello1
Hello2
Hello3
I want to have a git patch that will remove the file (myfile1.txt) after git apply.
And my patch (0001-delete-file.patch) look like this:
From 720a55f680189737b2af5494e189e1287c5a4207 Mon Sep 17 00:00:00 2001
From: ChunHau Tan <[email protected]>
Date: Thu, 2 Jan 2025 13:38:01 +0800
Subject: [PATCH] delete file
---
myfile1.txt | 3 ---
1 file changed, 3 deletions(-)
delete mode 100644 myfile1.txt
diff --git a/myfile1.txt b/myfile1.txt
deleted file mode 100644
index 697513d..0000000
--- a/myfile1.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-Hello1
-Hello2
-Hello3
--
2.34.1.windows.1
It looks like the patch file still contains the file's content:
@@ -1,3 +0,0 @@
-Hello1
-Hello2
-Hello3
If the file's content is changing, then I have to change the patch file.
Can we have a patch file that do the remove/delete file without considering its content ?
Please teach me how to create the patch. thank you very much !
I would like to create a .patch file that can remove/delete a file without considering its content.
In my git repo, I have myfile1.txt, its content:
Hello1
Hello2
Hello3
I want to have a git patch that will remove the file (myfile1.txt) after git apply.
And my patch (0001-delete-file.patch) look like this:
From 720a55f680189737b2af5494e189e1287c5a4207 Mon Sep 17 00:00:00 2001
From: ChunHau Tan <[email protected]>
Date: Thu, 2 Jan 2025 13:38:01 +0800
Subject: [PATCH] delete file
---
myfile1.txt | 3 ---
1 file changed, 3 deletions(-)
delete mode 100644 myfile1.txt
diff --git a/myfile1.txt b/myfile1.txt
deleted file mode 100644
index 697513d..0000000
--- a/myfile1.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-Hello1
-Hello2
-Hello3
--
2.34.1.windows.1
It looks like the patch file still contains the file's content:
@@ -1,3 +0,0 @@
-Hello1
-Hello2
-Hello3
If the file's content is changing, then I have to change the patch file.
Can we have a patch file that do the remove/delete file without considering its content ?
Please teach me how to create the patch. thank you very much !
rm -f myfile.txt
git diff myfile.txt > myfile.patch
git checkout myfile.txt #Only if you want to revert to the previous state
You won't need the git diff step if your goal is to just remove the file.
rm -f myfile.txt; git add myfile.txt; git commit -m "Commit message"
Should suffice. But yes, if you want a dynamically changing patch file, first set of steps ought to help.