$ cd /tmp $ mkdir am-nocontext $ cd am-nocontext $ git init Initialized empty Git repository in /tmp/am-nocontext/.git/ $ git config user.name "Joe Average" $ git config user.email "joe@example.com" $ printf "One\nTwo\nThree\n" > text.txt $ cat text.txt One Two Three $ git add text.txt $ git commit -m "Initial commit" [master (root-commit) e2e0c16] Initial commit 1 file changed, 3 insertions(+) create mode 100644 text.txt $ git log --pretty=oneline e2e0c16f6d31bc8e673494ecc92d1e8f377275aa (HEAD -> master) Initial commit $ printf "2d\nwq\n" | ed text.txt 14 10 $ cat text.txt One Three $ git diff diff --git a/text.txt b/text.txt index 4fcefbf..3146b8f 100644 --- a/text.txt +++ b/text.txt @@ -1,3 +1,2 @@ One -Two Three $ git commit -am "Removing second line" [master 27e6e8b] Removing second line 1 file changed, 1 deletion(-) $ git log --pretty=oneline 27e6e8bdc3ecbecc17f5ec1407f97f1977054461 (HEAD -> master) Removing second line e2e0c16f6d31bc8e673494ecc92d1e8f377275aa Initial commit $ git format-patch -U0 HEAD^ 0001-Removing-second-line.patch $ cat 0001-Removing-second-line.patch From 27e6e8bdc3ecbecc17f5ec1407f97f1977054461 Mon Sep 17 00:00:00 2001 From: Joe Average Date: Tue, 5 May 2020 18:17:52 +0700 Subject: [PATCH] Removing second line --- text.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/text.txt b/text.txt index 4fcefbf..3146b8f 100644 --- a/text.txt +++ b/text.txt @@ -2 +1,0 @@ One -Two -- 2.26.2 $ git reset --hard HEAD^ HEAD is now at e2e0c16 Initial commit $ git log --pretty=oneline e2e0c16f6d31bc8e673494ecc92d1e8f377275aa (HEAD -> master) Initial commit $ git am 0001-Removing-second-line.patch Applying: Removing second line error: patch failed: text.txt:2 error: text.txt: patch does not apply Patch failed at 0001 Removing second line hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". $ git am --abort $ git diff $ git log --pretty=oneline e2e0c16f6d31bc8e673494ecc92d1e8f377275aa (HEAD -> master) Initial commit $ git apply --verbose 0001-Removing-second-line.patch Checking patch text.txt... error: while searching for: Two error: patch failed: text.txt:2 error: text.txt: patch does not apply $ git log --pretty=oneline e2e0c16f6d31bc8e673494ecc92d1e8f377275aa (HEAD -> master) Initial commit $ git diff $ patch -p 1 -i 0001-Removing-second-line.patch patching file text.txt $ git diff diff --git a/text.txt b/text.txt index 4fcefbf..3146b8f 100644 --- a/text.txt +++ b/text.txt @@ -1,3 +1,2 @@ One -Two Three $ exit