Say my commit history looks like this:
A -- B -- C -- D (HEAD)
With a file test.txt, where each letter was added in the respective commit
A
B
C
D
Without changing the git history (just changing the working directory), I would like to undo the changes of commit B, while keeping the changes of commits C and D. If there is a conflict, add in the "conflict dividers"
diff --git a/t.txt b/t.txt
index 8422d40..d9a85ba 100644
--- a/t.txt
+++ b/t.txt
@@ -1,4 +1,3 @@
A
-B
C
D
edit
git revert -n B
was what I tried, but it just put all the changes in C and D into a conflict...
$ git revert -n 440e9c
Auto-merging t.txt
CONFLICT (content): Merge conflict in t.txt
error: could not revert 440e9c1... B
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
$ git diff
diff --cc t.txt
index 8422d40,760a73a..0000000
--- a/t.txt
+++ b/t.txt
@@@ -1,4 -1,2 +1,8 @@@
A
++<<<<<<< HEAD
+B
+C
+D
++=======
+
++>>>>>>> parent of 440e9c1 (B)
Say my commit history looks like this:
A -- B -- C -- D (HEAD)
With a file test.txt, where each letter was added in the respective commit
A
B
C
D
Without changing the git history (just changing the working directory), I would like to undo the changes of commit B, while keeping the changes of commits C and D. If there is a conflict, add in the "conflict dividers"
diff --git a/t.txt b/t.txt
index 8422d40..d9a85ba 100644
--- a/t.txt
+++ b/t.txt
@@ -1,4 +1,3 @@
A
-B
C
D
edit
git revert -n B
was what I tried, but it just put all the changes in C and D into a conflict...
$ git revert -n 440e9c
Auto-merging t.txt
CONFLICT (content): Merge conflict in t.txt
error: could not revert 440e9c1... B
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
$ git diff
diff --cc t.txt
index 8422d40,760a73a..0000000
--- a/t.txt
+++ b/t.txt
@@@ -1,4 -1,2 +1,8 @@@
A
++<<<<<<< HEAD
+B
+C
+D
++=======
+
++>>>>>>> parent of 440e9c1 (B)
Share
Improve this question
edited Mar 14 at 7:03
Tom Huntington
asked Mar 13 at 22:27
Tom HuntingtonTom Huntington
3,45514 silver badges33 bronze badges
4
B
, the lineB
was added betweenA
and andEOF
. When you committedC
,C
was added betweenB
andEOF
. If you try to revertB
,B
would try to be taken back betweenA
andEOF
which is not there anymore. You have aC
now afterB
so git has to show you conflict markers. – eftshift0 Commented Mar 14 at 7:17发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744681977a4587682.html