I tried revert but it kept giving me annoying conflictions.
I want something like this:
A-B-C-D-E-F
A-B-C-D-E-F-D'
is there a simple way of doing this.
As far as I can tell from your post and comments, you want to revert F and E, but keep them as history. What you can do is this:
git revert HEAD~n..HEAD Where you replace n with far however back from HEAD (your current commit) the commit after D is.
What this will do is revert every commit between HEAD and the commit after D in reverse order, ensuring no conflicts.
This becomes substantially more complicated when there are merge commits in that range. If there are, do something like this:
git revert -m 1 HEAD~n..HEAD Which will prefer the first parent branch of a merge commit, and remove changes introduced by merging in other branches. Do this with great care, as it may not end up doing what you actually want.
In opposition to the accepted answer, I would suggest (assuming that you are talking about the master branch, which you want to set back a few commits while keeping the skipped ones around somewhere):
git checkout master git checkout -b old_master git branch -f master D git checkout master This gives you a very clear history, and the junk you removed is still around
master | v A-B-C-D \ E-F ^ | old_master Any further commits will lead to a diverging history...
master | v A-B-C-D-G-H \ E-F ^ | old_master So E and F will never muddle up your "real" history, but you will always be able to get back to them. If and when you decide that you finally do not need them anymore, you just git branch -D old_master and they are gone without any trace.
EandFthat you want to preserve? Why not just revertFandEand be done with it? A revert on the currentHEADwill never cause a conflict.EandFare commits where I made my model more accurate but far slower compared toD. By doing what the OP wants, one can revert toDbut still revisitEandFand keep the learnings from the development process.