Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 917777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:15:50+00:00 2026-05-15T18:15:50+00:00

I was working with a friend on a project, and he edited a bunch

  • 0

I was working with a friend on a project, and he edited a bunch of files that shouldn’t have been edited. Somehow I merged his work into mine, either when I pulled it, or when I tried to just pick the specific files out that I wanted. I’ve been looking and playing for a long time, trying to figure out how to remove the commits that contain the edits to those files, it seems to be a toss up between revert and rebase, and there are no straightforward examples, and the docs assume I know more than I do.

So here is a simplified version of the question:

Given the following scenario, how do I remove commit 2?

$ mkdir git_revert_test && cd git_revert_test

$ git init
Initialized empty Git repository in /Users/josh/deleteme/git_revert_test/.git/

$ echo "line 1" > myfile

$ git add -A

$ git commit -m "commit 1"
[master (root-commit) 8230fa3] commit 1
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 myfile

$ echo "line 2" >> myfile

$ git commit -am "commit 2"
[master 342f9bb] commit 2
 1 files changed, 1 insertions(+), 0 deletions(-)

$ echo "line 3" >> myfile

$ git commit -am "commit 3"
[master 1bcb872] commit 3
 1 files changed, 1 insertions(+), 0 deletions(-)

The expected result is

$ cat myfile
line 1
line 3

Here is an example of how I have been trying to revert

$ git revert 342f9bb
Automatic revert failed.  After resolving the conflicts,
mark the corrected paths with 'git add <paths>' or 'git rm <paths>'
and commit the result.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:15:51+00:00Added an answer on May 15, 2026 at 6:15 pm

    The algorithm that Git uses when calculating diffs to be reverted requires that

    1. The lines being reverted are not modified by any later commits.
    2. There not be any other "adjacent" commits later in history.

    The definition of "adjacent" is based on the default number of lines from a context diff, which is 3. So if ‘myfile’ was constructed like this:

    $ cat >myfile <<EOF
    line 1
    junk
    junk
    junk
    junk
    line 2
    junk
    junk
    junk
    junk
    line 3
    EOF
    $ git add myfile
    $ git commit -m "initial check-in"
     1 files changed, 11 insertions(+), 0 deletions(-)
     create mode 100644 myfile
    
    $ perl -p -i -e 's/line 2/this is the second line/;' myfile
    $ git commit -am "changed line 2 to second line"
    [master d6cbb19] changed line 2
     1 files changed, 1 insertions(+), 1 deletions(-)
    
    $ perl -p -i -e 's/line 3/this is the third line/;' myfile
    $ git commit -am "changed line 3 to third line"
    [master dd054fe] changed line 3
     1 files changed, 1 insertions(+), 1 deletions(-)
    
    $ git revert d6cbb19
    Finished one revert.
    [master 2db5c47] Revert "changed line 2"
     1 files changed, 1 insertions(+), 1 deletions(-)
    

    Then it all works as expected.

    The second answer was very interesting. There is a feature that has not yet been officially released (though it is available in Git v1.7.2-rc2) called Revert Strategy. You can invoke git like this:

    git revert –strategy resolve <commit>

    and it should do a better job of figuring out what you meant. I do not know what the list of available strategies is, nor do I know the definition of any strategy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on a CodeIgniter project with a friend of mine for almost
I and my friend are working on a small Java EE project. But we
I'm working under project (using github) with my friend. The situation: My friend checkouted
This is supposed to be a working project from my friend. He demonstrated the
I am working on this project just trying to keep up my c++ knowledge.
Let me preface this question by saying that I am a .NET developer at
A friend and user of one of my open source apps has hired a
Given an enum similar to this: Friend Enum TestValue As Int32 tstNotSet = -1
I am having an strange problem in visual studio 2010, visual basic, and using
Question: What ruleset do I need to do the following redirects: [1] http://www.xyzblog.com/foo/bar.php =>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.