WhiteShadow WhiteShadow - 15 days ago 5
Git Question

How to solve a revert commit conflict

I am trying to learn how to use Git and GitHub. I've made a simple html file and I'm trying to revert some changes.

I am using GitHub windows application and the repository is here: https://github.com/ionutincau/Ceau

My last 2 commits are "Add 13 to list" and "Add Accounts to list". I want to revert the commit "Add 13 to list" but I get this file:

<!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>


What I need to do? How is this working?

Answer

That’s a simple conflict. If you didn’t add the accounts line, Git would figure out that reverting 76f0f70 is simply removing the 13 line. But now it hits the accounts line and says: “Whoa, I don’t know how to revert the changes from 76f0f70. I have marked the problematic part in the file, can you help me by hand?”

So you open the file, remove the unwanted 13 line and all the markers inserted by Git:

<body>
    <p>Salutare aceasta este prima versiune</p>
    <p>TODO List:</p>
    <p>- Poze</p>
    <p>- Accounts</p>
</body>

</html>

Now you can mark the conflict solved by running git add index.html and committing. The history will now be:

$ git log --pretty=oneline --abbrev-commit | head -n 3
02933f8 Revert "Add 13 to list"
d4b2377 Add Account
76f0f70 Add 13 to list

And the revert commit looks like this:

$ 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>

Of course, in this case it would be easier not to bother and simply delete the unwanted line without using git revert.

Comments