slimboy slimboy - 1 year ago 79
Git Question

How to make a copy of a previous git commit and make it head

I tried revert but it kept giving me annoying conflictions.

I want something like this:



is there a simple way of doing this.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download