2

This is what my commit history looks like (everything has been pushed to Github where my repo is stored, but I'm the only contributor):

                           master       
                             |
..-c100-c101-c102-c103-...-c150

I need to revert master to the c100 commit while keeping the remaining commits (ie: c101-c102...-c150), I don't want to loose them.

So this is what I came up with:

git checkout -b new-branch # Set up branch containing all commits
git checkout master        # Go back to master
git revert <c-100>         # Revert master branch to c-100 commit

which would (hopefully) result in:

   master
     |
..-c100-c101-c102-c103-...-c150
                             |
                        new-branch

Ideally I would then make a few commits to master to then leave it untouched until I can merge the new branch into it.

Is this the correct way to do this?


Add

Well just tried it and using git revert <SHA> does not work, it only reverts that commit.

Gabriel
  • 40,504
  • 73
  • 230
  • 404
  • git revert != snv revert. It sounds like you need to do `git reset --hard c100` followed by a force push. There are a lot of other threads on SO about this – Andrew C Nov 06 '14 at 13:41
  • I just tried the commands in my question and it didn't work, it only reverted _that_ commit, it didn't put `master` back to the state it was on that commit. So I guess you are right. – Gabriel Nov 06 '14 at 13:43

2 Answers2

1

This is perfectly normal. You could also just set a tag on the tip of the commit you want to commit.

Anorak
  • 3,096
  • 1
  • 14
  • 11
1

The answer was (as stated here) to use:

git revert --no-commit c-100..HEAD
git commit
Community
  • 1
  • 1
Gabriel
  • 40,504
  • 73
  • 230
  • 404