Checkout old commit and make it a new commit [duplicate]
git rm -r .
git checkout HEAD~3 .
git commit
After the commit, files in the new HEAD
will be the same as they were in the revision HEAD~3
.
It sounds like you just want to reset to C; that is make the tree:
A-B-C
You can do that with reset
:
git reset --hard HEAD~3
(Note: You said three commits ago so that's what I wrote; in your example C is only two commits ago, so you might want to use HEAD~2
)
You can also use revert
if you want, although as far as I know you need to do the reverts one at a time:
git revert HEAD # Reverts E
git revert HEAD~2 # Reverts D
That will create a new commit F that's the same contents as D, and G that's the same contents as C. You can rebase
to squash those together if you want
eloone did it file by file with
git checkout <commit-hash> <filename>
but you could checkout all files more easily by doing
git checkout <commit-hash> .