WhiteShadow
WhiteShadow

Reputation: 839

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?

Upvotes: 3

Views: 2716

Answers (4)

frank_liu
frank_liu

Reputation: 31

Let me show you root cause: "linefeed,new line, br"

first time you input <p>- 13</p> |(cursor is there)

the second time you input( <p>- Accounts</p>), git actually think you remove <p>- 13</p> and add new <p>- 13</p>,so the second time you just commit this content:

<p>- 13</p>
<p>- Accounts</p>

when you revert first time commit,git will generate new commit “revert commit” Conflict exist between second time commit and “revert commit”

solution A Actually,for this scenario,there is no need use revert command;just remove it manual solution B follow zoul answer

git revert: Why do I get conflicts? git revert: Why do I get conflicts?

Upvotes: 0

李其琛
李其琛

Reputation: 1

If your changed lines in two commits is neighbor, there will be a revert conflict. But if your change lines like this:

<body>
    <p>Hi, this is my first version</p>
    <p>TODO List:</p>
    <p>- Pictures</p>
    <p>- 13</p>
    something
    <p>- Accounts</p>
</body>

you revert and no conflict. There is the reason: Conflict while trying a revert in Git

Upvotes: 0

zoul
zoul

Reputation: 104125

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.

Upvotes: 4

DilumN
DilumN

Reputation: 2895

I went through your commit history. To remove your commit "Add 13 to list" first of all you have to take your head to commit "Refactor".

git reset --hard 8816fb
git cherry-pick d4b2377
git push origin HEAD --force

The first command will take your head to "Refactor"

Second command will pick your "Add Accounts to list" to master

Finally you have to push --force because you reset the head.

If you have any question or if I misunderstand your question, let me know

Upvotes: 0

Related Questions