Reputation: 2998
I'd like to reset a branch to a certain commit, but still keep its history. For example, given this branch:
A -> B -> C
I'd like to create a new commit A*
such that the branch at A
and the branch at A*
are exactly the same, and the history looks like:
A -> B -> C -> A*
Is this possible in git?
Upvotes: 1
Views: 41
Reputation: 30756
I can think of two approaches using git revert
.
Revert the last two commits. This creates two new commits. I'm using the --no-edit
flag here so it won't prompt you for a commit message for each revert.
git revert --no-edit HEAD^^..HEAD
Then, since you wanted one commit instead of two, do an interactive rebase to squash the two revert commits you just created.
git rebase -i HEAD^^
--no-commit
, then commitWith the --no-commit
flag, git revert
does not commit anything, but just makes changes to the working tree and index.
git revert --no-commit HEAD^^..HEAD
Then you can commit the change.
git commit
Upvotes: 4