如何解决还原提交冲突
How to solve a revert commit conflict
我正在尝试学习如何使用 Git 和 GitHub。我制作了一个简单的 html 文件,我正在尝试恢复一些更改。
我正在使用 GitHub windows 应用程序,存储库在这里:https://github.com/ionutincau/Ceau
我的最后 2 次提交是 "Add 13 to list" 和 "Add Accounts to list"。我想还原提交 "Add 13 to list" 但我得到了这个文件:
<!DOCTYPE html>
<html>
<head>
<title>Hi</title>
</head>
<body>
<p>Hi, this is my first version</p>
<p>TODO List:</p>
<p>- Pictures</p>
<<<<<<< HEAD
<p>- 13</p>
<p>- Accounts</p>
=======
>>>>>>> parent of 76f0f70... Add 13 to list
</body>
</html>
我需要做什么?这是如何工作的?
我查看了你的提交历史。要删除您的提交 "Add 13 to list" 首先,您必须认真提交 "Refactor".
git reset --hard 8816fb
git cherry-pick d4b2377
git push origin HEAD --force
第一个命令会将您带到 "Refactor"
第二个命令将选择你的"Add Accounts to list"来掌握
最后你必须按下 --force 因为你重置了头部。
如果您有任何问题或者我误解了您的问题,请告诉我
这是一个简单的冲突。如果您没有添加 accounts 行,Git 会发现还原 76f0f70 只是删除 13 行。但现在它点击 accounts 行并说:“哇,我不知道如何恢复 76f0f70 的更改。我已经在文件中标记了有问题的部分,你能帮我手工吗?”
因此您打开文件,删除不需要的 13 行和 Git:
插入的所有标记
<body>
<p>Salutare aceasta este prima versiune</p>
<p>TODO List:</p>
<p>- Poze</p>
<p>- Accounts</p>
</body>
</html>
现在您可以将冲突标记为 运行 git add index.html
并提交。历史现在将是:
$ git log --pretty=oneline --abbrev-commit | head -n 3
02933f8 Revert "Add 13 to list"
d4b2377 Add Account
76f0f70 Add 13 to list
还原提交看起来像这样:
$ git show --oneline 02933f8
02933f8 Revert "Add 13 to list"
diff --git a/index.html b/index.html
index 9f99341..6bec1cf 100644
--- a/index.html
+++ b/index.html
@@ -9,8 +9,7 @@
<p>Salutare aceasta este prima versiune</p>
<p>TODO List:</p>
<p>- Poze</p>
- <p>- 13</p>
<p>- Accounts</p>
</body>
当然,在这种情况下,不使用 git revert
.
直接删除不需要的行会更容易
如果您在两个提交中更改的行是相邻的,则会发生还原冲突。但是,如果您像这样更改行:
<body>
<p>Hi, this is my first version</p>
<p>TODO List:</p>
<p>- Pictures</p>
<p>- 13</p>
something
<p>- Accounts</p>
</body>
你恢复了,没有冲突。
是有原因的:
Conflict while trying a revert in Git
让我告诉你根本原因:
"linefeed,new line, br"
第一次输入
<p>- 13</p>
|(光标在那里)
第二次输入(<p>- Accounts</p>
),git居然以为你
删除 <p>- 13</p>
并添加新的 <p>- 13</p>
,因此您第二次只需提交此内容:
<p>- 13</p>
<p>- Accounts</p>
当你恢复第一次提交时,git会生成新的提交“revert commit”
第二次提交和“恢复提交”之间存在冲突
解决方案A
其实对于这种场景,不需要使用revert命令,手动去掉即可
溶液B
关注 zoul 的回答
git revert: Why do I get conflicts?
git revert: Why do I get conflicts?
我正在尝试学习如何使用 Git 和 GitHub。我制作了一个简单的 html 文件,我正在尝试恢复一些更改。
我正在使用 GitHub windows 应用程序,存储库在这里:https://github.com/ionutincau/Ceau
我的最后 2 次提交是 "Add 13 to list" 和 "Add Accounts to list"。我想还原提交 "Add 13 to list" 但我得到了这个文件:
<!DOCTYPE html>
<html>
<head>
<title>Hi</title>
</head>
<body>
<p>Hi, this is my first version</p>
<p>TODO List:</p>
<p>- Pictures</p>
<<<<<<< HEAD
<p>- 13</p>
<p>- Accounts</p>
=======
>>>>>>> parent of 76f0f70... Add 13 to list
</body>
</html>
我需要做什么?这是如何工作的?
我查看了你的提交历史。要删除您的提交 "Add 13 to list" 首先,您必须认真提交 "Refactor".
git reset --hard 8816fb
git cherry-pick d4b2377
git push origin HEAD --force
第一个命令会将您带到 "Refactor"
第二个命令将选择你的"Add Accounts to list"来掌握
最后你必须按下 --force 因为你重置了头部。
如果您有任何问题或者我误解了您的问题,请告诉我
这是一个简单的冲突。如果您没有添加 accounts 行,Git 会发现还原 76f0f70 只是删除 13 行。但现在它点击 accounts 行并说:“哇,我不知道如何恢复 76f0f70 的更改。我已经在文件中标记了有问题的部分,你能帮我手工吗?”
因此您打开文件,删除不需要的 13 行和 Git:
插入的所有标记<body>
<p>Salutare aceasta este prima versiune</p>
<p>TODO List:</p>
<p>- Poze</p>
<p>- Accounts</p>
</body>
</html>
现在您可以将冲突标记为 运行 git add index.html
并提交。历史现在将是:
$ git log --pretty=oneline --abbrev-commit | head -n 3
02933f8 Revert "Add 13 to list"
d4b2377 Add Account
76f0f70 Add 13 to list
还原提交看起来像这样:
$ git show --oneline 02933f8
02933f8 Revert "Add 13 to list"
diff --git a/index.html b/index.html
index 9f99341..6bec1cf 100644
--- a/index.html
+++ b/index.html
@@ -9,8 +9,7 @@
<p>Salutare aceasta este prima versiune</p>
<p>TODO List:</p>
<p>- Poze</p>
- <p>- 13</p>
<p>- Accounts</p>
</body>
当然,在这种情况下,不使用 git revert
.
如果您在两个提交中更改的行是相邻的,则会发生还原冲突。但是,如果您像这样更改行:
<body>
<p>Hi, this is my first version</p>
<p>TODO List:</p>
<p>- Pictures</p>
<p>- 13</p>
something
<p>- Accounts</p>
</body>
你恢复了,没有冲突。 是有原因的: Conflict while trying a revert in Git
让我告诉你根本原因: "linefeed,new line, br"
第一次输入
<p>- 13</p>
|(光标在那里)
第二次输入(<p>- Accounts</p>
),git居然以为你
删除 <p>- 13</p>
并添加新的 <p>- 13</p>
,因此您第二次只需提交此内容:
<p>- 13</p>
<p>- Accounts</p>
当你恢复第一次提交时,git会生成新的提交“revert commit” 第二次提交和“恢复提交”之间存在冲突
解决方案A 其实对于这种场景,不需要使用revert命令,手动去掉即可 溶液B 关注 zoul 的回答
git revert: Why do I get conflicts? git revert: Why do I get conflicts?