views:

36

answers:

1

Let's say someone has updated the remote origin with some nonsense and I want to ignore it. My repo looks like

A-B-C-D

And the remote is

A-B-C-D-E-F

I basically want to ditch E & F, but keep the history, so hopefully the result would look like

      /-----\
A-B-C-D-E-F-G

I can't see how to reset or revert without replaying E & F on top. I can't see how to merge without keeping E & F's changes. G & D should be precisely the same basically.

+3  A: 

So, you want to undo the changes in E and F, but retain E and F in the history? Use git revert with the -n (no commit) option:

$ git revert -n $F
$ git revert -n $E
# Fix conflicts, check to make sure the reverts look good, etc.
$ git commit
mipadi
Why would I need the two revert commands with both F then E? I got it working with a test repo, and happily reverted back after some monster merging. Is there an easy way to just accept ALL of targets changes?
Wil
`git revert` only reverts one commit at a time; I was under the impression you wanted to revert *both* commits in a *single* revert commit.
mipadi
Wil
It doesn't reset the HEAD to the previous state (that's what `git reset` does); `git revert` actually creates a *new* commit that undoes the given commit. If you revert E, you'll only have reverted the changes introduced in E, not the changes introduced in both E and F. (Maybe this'll work in your specific case -- I don't know all the details of your commit history -- but in general, it probably won't.)
mipadi